]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for sketcher abort problem
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 28 Nov 2014 14:37:35 +0000 (17:37 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 28 Nov 2014 14:37:35 +0000 (17:37 +0300)
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_WidgetPoint2d.cpp

index 0ab84bf8260d8d9f8683abe29d1977b6beb48259..44deb41e4c973388160362226e2863c303a54b4d 100644 (file)
@@ -56,7 +56,7 @@
 //#include <Config_PointerMessage.h>
 //#include <Config_ModuleReader.h>
 //#include <Config_WidgetReader.h>
-//#include <Events_Loop.h>
+#include <Events_Loop.h>
 //#include <Events_Message.h>
 //#include <Events_Error.h>
 
@@ -195,10 +195,15 @@ void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation)
 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
 {
   if (theOperation->id().toStdString() == SketchPlugin_Sketch::ID()) {
+    DataPtr aData = myCurrentSketch->data();
+    if ((!aData) || (!aData->isValid())) {
+      // The sketch was aborted
+      myCurrentSketch = CompositeFeaturePtr();
+      return; 
+    }
     // Hide all sketcher sub-Objects
     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
-
     for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
       FeaturePtr aFeature = myCurrentSketch->subFeature(i);
       std::list<ResultPtr> aResults = aFeature->results();
@@ -235,7 +240,7 @@ void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
         if (aPoint) {
           aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
           PartSet_Tools::setConstraints(myCurrentSketch, theOperation->feature(), 
-            SketchPlugin_Line::START_ID(), aPoint->x(), aPoint->y());
+            aWgt->attributeID(), aPoint->x(), aPoint->y());
           theOperation->propertyPanel()->activateNextWidget(aPnt2dWgt);
         }
       }
@@ -341,7 +346,6 @@ void PartSet_Module::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent*
       // This is necessary in order to finalize previous operation
       QApplication::processEvents();
       launchEditing();
-      //QTimer::singleShot(10, this, SLOT(launchEditing()));
     }
   }
 }
@@ -382,22 +386,34 @@ void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent
 void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
   if (myIsDragging) {
+    ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
+    if (aOperation->id().toStdString() == SketchPlugin_Sketch::ID())
+      return; // No edit operation activated
+
+    static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
     Handle(V3d_View) aView = theWnd->v3dView();
     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
     double aX, aY;
     PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, aY);
-    double dX = myCurX - aX;
-    double dY = myCurY - aY;
-
-    ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
-    ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
-    QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
-    foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
-      PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
-      if (aWgt2d) {
-        aWgt2d->setPoint(aWgt2d->x() - dX, aWgt2d->y() - dY);
+    double dX =  aX - myCurX;
+    double dY =  aY - myCurY;
+
+    std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+      std::dynamic_pointer_cast<SketchPlugin_Feature>(aOperation->feature());
+    if (aSketchFeature) { 
+      aSketchFeature->move(dX, dY);
+      ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent);
+      Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+    }/* else { // Alternative case for moving
+      ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+      QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
+      foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
+        PartSet_WidgetPoint2D* aWgt2d = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
+        if (aWgt2d) {
+          aWgt2d->setPoint(aWgt2d->x() + dX, aWgt2d->y() + dY);
+        }
       }
-    }
+    }*/
     myDragDone = true;
     myCurX = aX;
     myCurY = aY;
@@ -430,9 +446,6 @@ void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& t
     const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
     if (aWidgets.last() == aPanel->activeWidget()) {
       breakOperationSequence();
-      PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aPanel->activeWidget());
-      PartSet_Tools::setConstraints(myCurrentSketch, aOperation->feature(), 
-        SketchPlugin_Line::END_ID(), aPnt2dWgt->x(), aPnt2dWgt->y());
     }
   }
 }
index 70b21db9e94daccf88bb3d40b2bcbb107308b0bd..4e73b4b4c3a7f80c9e60aa1d2f947a633f7b0964 100644 (file)
@@ -231,6 +231,8 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous
           double aX, aY;
           PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY);
           setPoint(aX, aY);
+
+          PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
           emit vertexSelected(aObjects.front(), aShape);
           QApplication::processEvents();
           emit focusOutWidget(this);