Salome HOME
Issue #2206 Avoid the ability to cancel the current sketch when saving,
[modules/shaper.git] / src / PartSet / PartSet_SketcherMgr.cpp
index 40625ee9e4ce5476d11c4b3ee50d99c38595d5ba..88334e9ee5b4eee569cb3c1b624283e4cf63e653 100755 (executable)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        PartSet_SketcherMgr.cpp
-// Created:     19 Dec 2014
-// Author:      Vitaly SMETANNIKOV
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #include "PartSet_SketcherMgr.h"
 #include "PartSet_SketcherReentrantMgr.h"
@@ -13,6 +27,7 @@
 #include "PartSet_WidgetEditor.h"
 #include "PartSet_ResultSketchPrs.h"
 #include "PartSet_ExternalPointsMgr.h"
+#include "PartSet_PreviewSketchPlane.h"
 
 #include <XGUI_ModuleConnector.h>
 #include <XGUI_Displayer.h>
@@ -69,6 +84,7 @@
 #include <SketchPlugin_MultiRotation.h>
 #include <SketchPlugin_MultiTranslation.h>
 #include <SketchPlugin_IntersectionPoint.h>
+#include <SketchPlugin_Projection.h>
 
 #include <SketcherPrs_Tools.h>
 
@@ -165,6 +181,8 @@ PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
   myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
   myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
   myIsConstraintsShown[PartSet_Tools::Expressions] = false;
+
+  mySketchPlane = new PartSet_PreviewSketchPlane();
 }
 
 PartSet_SketcherMgr::~PartSet_SketcherMgr()
@@ -523,15 +541,12 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
     Point aMousePnt;
     get2dPoint(theWnd, theEvent, aMousePnt);
-#ifndef SUPPORT_NEW_MOVE
-    double dX =  aMousePnt.myCurX - myCurrentPoint.myCurX;
-    double dY =  aMousePnt.myCurY - myCurrentPoint.myCurY;
-#else
+
     std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition = std::shared_ptr<GeomAPI_Pnt2d>(
                             new GeomAPI_Pnt2d(myCurrentPoint.myCurX, myCurrentPoint.myCurY));
     std::shared_ptr<GeomAPI_Pnt2d> aCurrentPosition = std::shared_ptr<GeomAPI_Pnt2d>(
                             new GeomAPI_Pnt2d(aMousePnt.myCurX, aMousePnt.myCurY));
-#endif
+
     ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
@@ -565,17 +580,14 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
               std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
             if (aPoint.get() != NULL) {
               bool isImmutable = aPoint->setImmutable(true);
-#ifndef SUPPORT_NEW_MOVE
-              aPoint->move(dX, dY);
-              ModelAPI_EventCreator::get()->sendUpdated(aFeature, aMoveEvent);
-#else
+
               std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
                        <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
               aMessage->setMovedAttribute(aPoint);
               aMessage->setOriginalPosition(anOriginalPosition);
               aMessage->setCurrentPosition(aCurrentPosition);
               Events_Loop::loop()->send(aMessage);
-#endif
+
               isModified = true;
               aPoint->setImmutable(isImmutable);
             }
@@ -586,17 +598,12 @@ void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEve
         std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
         if (aSketchFeature) {
-#ifndef SUPPORT_NEW_MOVE
-          aSketchFeature->move(dX, dY);
-          ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, aMoveEvent);
-#else
           std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
                     <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
           aMessage->setMovedObject(aFeature);
           aMessage->setOriginalPosition(anOriginalPosition);
           aMessage->setCurrentPosition(aCurrentPosition);
           Events_Loop::loop()->send(aMessage);
-#endif
           isModified = true;
         }
       }
@@ -716,8 +723,15 @@ void PartSet_SketcherMgr::launchEditing()
     FeaturePtr aFeature = myCurrentSelection.begin().key();
     std::shared_ptr<SketchPlugin_Feature> aSPFeature =
               std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
-    if (aSPFeature && (!aSPFeature->isExternal())) {
-      myModule->editFeature(aSPFeature);
+    if (aSPFeature) {
+      if (!aSPFeature->isExternal())
+        myModule->editFeature(aSPFeature);
+      else {
+        FeaturePtr aProjectionFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
+                                                        SketchPlugin_Projection::ID());
+        if (aProjectionFeature.get())
+          myModule->editFeature(aProjectionFeature);
+      }
     }
   }
 }
@@ -912,6 +926,7 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
 
   // Display all sketcher sub-Objects
   myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
+  mySketchPlane->createSketchPlane(myCurrentSketch, myModule->workshop());
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
 
   // Hide sketcher result
@@ -1033,6 +1048,7 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
     XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
     // The sketch was aborted
     myCurrentSketch = CompositeFeaturePtr();
+    mySketchPlane->eraseSketchPlane(myModule->workshop());
     // TODO: move this outside of if-else
     myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
     myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
@@ -1076,13 +1092,13 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
       myCurrentSketch->setDisplayed(true);
 
     myCurrentSketch = CompositeFeaturePtr();
+    mySketchPlane->eraseSketchPlane(myModule->workshop());
 
     myModule->workshop()->viewer()->removeSelectionFilter(myCirclePointFilter);
     myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter);
 
     Events_Loop::loop()->flush(aDispEvent);
   }
-  myModule->overconstraintListener()->setActive(false);
   // restore the module selection modes, which were changed on startSketch
   aConnector->activateModuleSelectionModes();
 }
@@ -1102,6 +1118,7 @@ void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
 
 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
 {
+  previewSketchPlane()->updatePlaneSize(activeSketch(), myModule->workshop());
   myIsMouseOverViewProcessed = true;
   operationMgr()->onValidateOperation();
   // when sketch nested operation is stopped the cursor should be restored unconditionally