From: Matthew G. <mat...@us...> - 2007-03-04 03:03:35
|
Update of /cvsroot/jsbsimcommander/src/gui In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26867/src/gui Modified Files: shape.cpp shape.h Log Message: Fix the bug when we insert a component into two. Index: shape.cpp =================================================================== RCS file: /cvsroot/jsbsimcommander/src/gui/shape.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** shape.cpp 3 Mar 2007 13:08:12 -0000 1.13 --- shape.cpp 4 Mar 2007 03:03:31 -0000 1.14 *************** *** 263,266 **** --- 263,310 ---- } + void MyEvtHandler::FindOneSegment(wxNode* &first, unsigned int &j, wxNode* last) + { + // shift the dup control points + wxRealPoint* p1; + wxRealPoint* p2 = (wxRealPoint*)last->GetData(); + while (first && (p1 = (wxRealPoint*)first->GetData()) + && fabs(p1->x - p2->x) < 1e-4 + && fabs(p1->y - p2->y) < 1e-4 ) + { + first = first->GetNext(); + ++j; + } + + // shift the lines in the same slope + double dx,dy; + if (first) + { + dy = p1->y - p2->y; + dx = p1->x - p2->x; + wxNode * prio = first->GetNext(); + while (prio) + { + p1 = (wxRealPoint*)first->GetData(); + p2 = (wxRealPoint*)prio->GetData(); + double ddx, ddy; + ddy = p1->y - p2->y; + ddx = p1->x - p2->x; + + if ( fabs(ddx) < 1e-4 && fabs(ddy) < 1e-4 + || fabs(ddx) < 1e-4 && fabs(dx) < 1e-4 && dy*ddy>0 + || fabs(dy / dx - ddy/ddx) < 1e-4) + { + first = prio; + ++j; + prio = prio->GetNext(); + } + else + { + break; + } + } + } + } + void MyEvtHandler::OnEndDragLeft(double x, double y, int keys, int attachment) { *************** *** 293,300 **** bool flag = false; wxList * cp = current->GetLineControlPoints(); ! wxNode * first = cp->GetFirst(); ! wxNode * last = first; ! first = first->GetNext(); unsigned int i=0; while (first) { --- 337,349 ---- bool flag = false; wxList * cp = current->GetLineControlPoints(); ! // find first segment line ! wxNode * last = cp->GetFirst(); unsigned int i=0; + // one step + wxNode *first = last->GetNext(); + unsigned int j=1; + + FindOneSegment(first, j, last); + while (first) { *************** *** 314,323 **** } last = first; first = first->GetNext(); ! ++i; } if (flag) { ! //TODO now we can insert the ComponentShape into the two MISOShape. { std::cout << "MyEvtHandler::OnEndDragLeft for ComponentShape without lines and find the line" << std::endl; --- 363,376 ---- } last = first; + i = j; first = first->GetNext(); ! ++j; ! ! FindOneSegment(first, j, last); } if (flag) { ! //Now we can insert the ComponentShape into the two MISOShape. ! /************************************************************* { std::cout << "MyEvtHandler::OnEndDragLeft for ComponentShape without lines and find the line" << std::endl; *************** *** 333,336 **** --- 386,390 ---- } } + ***************************************************************/ wxShape *from = current->GetFrom(); wxShape *to = current->GetTo(); *************** *** 357,363 **** from->AddLine ((wxLineShape *) theShape, cshape, attachFrom, 1); first = cp->GetFirst(); ! for (int j=0; j<i+2; ++j) { ! *((wxRealPoint *) lineShape->GetLineControlPoints ()->Item (j)-> GetData ()) = *((wxRealPoint *) first->GetData()); first = first->GetNext(); --- 411,417 ---- from->AddLine ((wxLineShape *) theShape, cshape, attachFrom, 1); first = cp->GetFirst(); ! for (int k=0; k<i+2; ++k) { ! *((wxRealPoint *) lineShape->GetLineControlPoints ()->Item (k)-> GetData ()) = *((wxRealPoint *) first->GetData()); first = first->GetNext(); *************** *** 368,372 **** theShape->Show (true); ! wxRealPoint* startp = (wxRealPoint*)cp->Item(i)->GetData(); cshape->GetAttachmentPosition (0, &(startp->x), &(startp->y)); first = cp->GetFirst(); --- 422,426 ---- theShape->Show (true); ! wxRealPoint* startp = (wxRealPoint*)cp->Item(j-1)->GetData(); cshape->GetAttachmentPosition (0, &(startp->x), &(startp->y)); first = cp->GetFirst(); *************** *** 378,381 **** --- 432,436 ---- } current->Straighten(); + MISOShape::NormalizeLine(current); { Index: shape.h =================================================================== RCS file: /cvsroot/jsbsimcommander/src/gui/shape.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** shape.h 3 Mar 2007 13:08:12 -0000 1.8 --- shape.h 4 Mar 2007 03:03:31 -0000 1.9 *************** *** 51,54 **** --- 51,58 ---- void OnEndDragRight(double x, double y, int keys = 0, int attachment = 0); void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0); + + protected: + /// find one look-like Segment Line from a line list start from last. + void FindOneSegment(wxNode* &first, unsigned int &j, wxNode* last); }; |