From: Matthew G. <mat...@us...> - 2007-03-02 03:27:22
|
Update of /cvsroot/jsbsimcommander/src/gui In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv23121/src/gui Modified Files: shape.cpp shape.h Log Message: Initial work to insert a single shape into tow connected shapes. Index: shape.cpp =================================================================== RCS file: /cvsroot/jsbsimcommander/src/gui/shape.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** shape.cpp 14 Jul 2006 01:42:08 -0000 1.11 --- shape.cpp 2 Mar 2007 03:26:59 -0000 1.12 *************** *** 263,266 **** --- 263,341 ---- } + void MyEvtHandler::OnEndDragLeft(double x, double y, int keys, int attachment) + { + wxShapeEvtHandler::OnEndDragLeft(x, y, keys, attachment); + + ComponentShape * cshape = wxDynamicCast( GetShape(), ComponentShape); + if (cshape) + { + if (cshape->GetLines().IsEmpty()) + { + double width = 0.0, height = 0.0; + cshape->GetBoundingBoxMin(&width, &height); + if (width < 4.0) width = 4.0; + if (height < 4.0) height = 4.0; + + double left = (double)(cshape->GetX() - (width/2.0)); + double top = (double)(cshape->GetY() - (height/2.0)); + double right = (double)(cshape->GetX() + (width/2.0)); + double bottom = (double)(cshape->GetY() + (height/2.0)); + + MyCanvas *canvas = (MyCanvas *) GetShape()->GetCanvas (); + wxDiagram * diagram = canvas->GetDiagram(); + wxList * shapes = diagram->GetShapeList(); + // let's iterate over the list + for ( wxNode *node = shapes->GetFirst(); node; node = node->GetNext() ) + { + wxLineShape *current = wxDynamicCast(node->GetData(), wxLineShape); + if (current) + { + bool flag = false; + wxList * cp = current->GetLineControlPoints(); + wxNode * first = cp->GetFirst(); + wxNode * last = first; + first = first->GetNext(); + unsigned int i=1; + while (first) + { + wxRealPoint* p1 = (wxRealPoint*)first->GetData(); + wxRealPoint* p2 = (wxRealPoint*)last->GetData(); + double l = p1->x < p2->x ? p1->x : p2->x ; + double r = p1->x > p2->x ? p1->x : p2->x ; + double t = p1->y < p2->y ? p1->y : p2->y ; + double b = p1->y > p2->y ? p1->y : p2->y ; + // Check whether the line is cross the shape. + // TODO too simple method to check. + if (l < left && r > right && t >= top && b <= bottom + || l >= left && r <= right && t < top && b > bottom) + { + flag = true; + break; + } + 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; + MISOShape * from = wxDynamicCast(current->GetFrom(), MISOShape); + if (from) + { + std::cout << "From:" << from->GetName() << ", Type:" << from->GetType() << endl; + } + MISOShape * to = wxDynamicCast(current->GetTo(), MISOShape); + if (to) + { + std::cout << "To:" << to->GetName() << ", Type:" << to->GetType() << endl; + } + break; + } + } + } + } + } + } /* Index: shape.h =================================================================== RCS file: /cvsroot/jsbsimcommander/src/gui/shape.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** shape.h 14 Jul 2006 01:42:08 -0000 1.6 --- shape.h 2 Mar 2007 03:26:59 -0000 1.7 *************** *** 50,53 **** --- 50,54 ---- void OnDragRight(bool draw, double x, double y, int keys = 0, int attachment = 0); void OnEndDragRight(double x, double y, int keys = 0, int attachment = 0); + void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0); }; |