Salome HOME
Issues #2027: trim on cirlce(arc will be created). Result of selected will clear...
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index bda26290a2da2ab3484260512f6236a4ab5f31c5..41c2d3b04db528cb807b85e8bab3ff3fd3310732 100755 (executable)
@@ -6,16 +6,16 @@
 #include "PartSet_Tools.h"
 #include "PartSet_PreviewPlanes.h"
 #include "PartSet_WidgetPoint2d.h"
-#include "PartSet_WidgetPoint2dDistance.h"
 #include "PartSet_WidgetPoint2DFlyout.h"
 #include "PartSet_WidgetShapeSelector.h"
 #include "PartSet_WidgetMultiSelector.h"
 #include "PartSet_WidgetSubShapeSelector.h"
+#include "PartSet_WidgetFeaturePointSelector.h"
 #include "PartSet_WidgetEditor.h"
 #include "PartSet_WidgetFileSelector.h"
 #include "PartSet_WidgetSketchCreator.h"
 #include "PartSet_SketcherMgr.h"
-#include "PartSet_SketcherReetntrantMgr.h"
+#include "PartSet_SketcherReentrantMgr.h"
 #include "PartSet_ResultSketchPrs.h"
 #include "PartSet_MenuMgr.h"
 #include "PartSet_CustomPrs.h"
@@ -37,7 +37,6 @@
 #include <ModuleBase_IPropertyPanel.h>
 #include <ModuleBase_WidgetEditor.h>
 #include <ModuleBase_WidgetValidated.h>
-#include <ModuleBase_FilterFactory.h>
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_OperationFeature.h>
 #include <ModuleBase_WidgetFactory.h>
 #include <Config_PropManager.h>
 #include <Config_Keywords.h>
 
+#include <AIS_Dimension.hxx>
+#include <AIS_InteractiveObject.hxx>
 #include <StdSelect_TypeOfFace.hxx>
 #include <TopoDS_Vertex.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
 #include <BRep_Tool.hxx>
-#include <AIS_Dimension.hxx>
 
 #include <QObject>
 #include <QMouseEvent>
@@ -131,7 +131,7 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   new PartSet_IconFactory();
 
   mySketchMgr = new PartSet_SketcherMgr(this);
-  mySketchReentrantMgr = new PartSet_SketcherReetntrantMgr(theWshop);
+  mySketchReentrantMgr = new PartSet_SketcherReentrantMgr(theWshop);
 
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWshop);
   XGUI_Workshop* aWorkshop = aConnector->workshop();
@@ -165,6 +165,9 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
   Config_PropManager::registerProp("Visualization", "operation_highlight_color",
                           "Multi selector item color in operation", Config_Prop::Color,
                           PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
+  Config_PropManager::registerProp("Visualization", "operation_remove_feature_color",
+                          "Color of removed feature in operation", Config_Prop::Color,
+                          PartSet_CustomPrs::OPERATION_REMOVE_FEATURE_COLOR());
 }
 
 PartSet_Module::~PartSet_Module()
@@ -230,23 +233,10 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
   aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
-}
-
-void PartSet_Module::registerFilters()
-{
-  //Registering of selection filters
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
-  ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
-}
-
-void PartSet_Module::registerProperties()
-{
-  Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_size", "Size", Config_Prop::Double,
-                                   PLANE_SIZE);
-  Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_thickness", "Thickness",
-                                   Config_Prop::Integer, SKETCH_WIDTH);
-  Config_PropManager::registerProp(SKETCH_TAB_NAME, "rotate_to_plane",
-    "Rotate to plane when selected", Config_Prop::Boolean, "false");
+  aFactory->registerValidator("PartSet_MultyTranslationSelection",
+    new PartSet_MultyTranslationSelection);
+  aFactory->registerValidator("PartSet_SplitSelection", new PartSet_SplitSelection);
+  aFactory->registerValidator("PartSet_ProjectionSelection", new PartSet_ProjectionSelection);
 }
 
 void PartSet_Module::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
@@ -335,7 +325,6 @@ void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
         }
       }
     } if (!isOperationCommitted) {
-      workshop()->updateCommandStatus();
       aWorkshop->connectToPropertyPanel(true);
       updateSketcherOnStart(aFOperation);
       updatePresentationsOnStart(aFOperation);
@@ -356,6 +345,10 @@ void PartSet_Module::operationStarted(ModuleBase_Operation* theOperation)
         XGUI_Displayer* aDisplayer = aWorkshop->displayer();
         aDisplayer->updateViewer();
       }
+      /// state of command actions should be updated after displayed objects modification because
+      /// deactivation(for example) of objects may influence on selection in the viewer
+      /// State of command actions may depend on selection in the viewer(e.g. Sketch)
+      workshop()->updateCommandStatus();
     }
     if (aPostonedWidgetActivation) {
       // if the widget is an empty in the chain of activated widgets, the current operation
@@ -519,7 +512,7 @@ bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const
 {
   bool isEnabledFixed = false;
   if (theActionId == XGUI_ActionsMgr::AcceptAll &&
-      mySketchReentrantMgr->isInternalEditStarted())
+      mySketchReentrantMgr->isInternalEditActive())
     isEnabledFixed = true;
   return isEnabledFixed;
 }
@@ -559,6 +552,17 @@ void PartSet_Module::customSubShapesSelectionModes(QIntList& theTypes)
     theTypes.append(SketcherPrs_Tools::Sel_Sketch_Wire);
 }
 
+void PartSet_Module::getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelected,
+                                      ObjectPtr& theObject, AttributePtr& theAttribute)
+{
+  ObjectPtr anObject = theSelected->object();
+  GeomShapePtr aShape = theSelected->shape();
+
+  theAttribute = findAttribute(anObject, aShape);
+  // TODO: try to create result if object is an external object
+  theObject = anObject;
+}
+
 bool PartSet_Module::isMouseOverWindow()
 {
   return mySketchMgr->isMouseOverWindow();
@@ -567,7 +571,7 @@ bool PartSet_Module::isMouseOverWindow()
 bool PartSet_Module::isSketchNeutralPointActivated() const
 {
   bool isNeutralPoint = true;
-  if (sketchReentranceMgr()->isInternalEditStarted())
+  if (sketchReentranceMgr()->isInternalEditActive())
     isNeutralPoint = false;
   if (myIsOperationIsLaunched)
     isNeutralPoint = false;
@@ -577,6 +581,7 @@ bool PartSet_Module::isSketchNeutralPointActivated() const
 
 void PartSet_Module::closeDocument()
 {
+  myActivePartIndex = QModelIndex();
   clearViewer();
 }
 
@@ -625,6 +630,13 @@ bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
       // click on the digit of dimension constrain comes here
       // with an empty shape, so we need the check
       if (aFeature == anOpFeature && aShape.get() && !aShape->isNull()) {
+        // if feature has only one result and shape of result is equal to selected shape
+        // this attribute is not processed. It is a case of Sketch Point.
+        if (aFeature->results().size() == 1) {
+          ResultPtr aResult = aFeature->results().front();
+          if (aResult.get() && aResult->shape()->isEqual(aShape))
+            return aProcessed;
+        }
         const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
         AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aTDShape,
                                                                mySketchMgr->activeSketch());
@@ -714,11 +726,6 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
     aPointWgt->setSketch(mySketchMgr->activeSketch());
     connect(aPointWgt, SIGNAL(vertexSelected()), sketchReentranceMgr(), SLOT(onVertexSelected()));
     aWgt = aPointWgt;
-  } else if (theType == "point2ddistance") {
-    PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent,
-                                                                     aWorkshop, theWidgetApi);
-    aDistanceWgt->setSketch(mySketchMgr->activeSketch());
-    aWgt = aDistanceWgt;
   } else if (theType == "sketch_shape_selector") {
     PartSet_WidgetShapeSelector* aShapeSelectorWgt =
                           new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi);
@@ -736,6 +743,12 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
     aSubShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
     aWgt = aSubShapeSelectorWgt;
   }
+  else if (theType == "sketch_feature_point_selector") {
+    PartSet_WidgetFeaturePointSelector* aPointSelectorWgt =
+            new PartSet_WidgetFeaturePointSelector(theParent, aWorkshop, theWidgetApi);
+    aPointSelectorWgt->setSketcher(mySketchMgr->activeSketch());
+    aWgt = aPointSelectorWgt;
+  }
   else if (theType == WDG_DOUBLEVALUE_EDITOR) {
     aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi);
   } else if (theType == "export_file_selector") {
@@ -1013,41 +1026,10 @@ bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr the
     return aCustomized;
 
   if (!theResult.get()) {
-    bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
-    // customize sketch symbol presentation
-    if (thePrs.get()) {
-      Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
-      if (!anAISIO.IsNull()) {
-        if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
-          Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
-          if (!aPrs.IsNull()) {
-            std::vector<int> aColor;
-            myOverconstraintListener->getConflictingColor(aColor);
-            aPrs->SetConflictingConstraint(isConflicting, aColor);
-            aCustomized = true;
-          }
-        } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
-          Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
-          if (!aPrs.IsNull()) {
-            std::vector<int> aColor;
-            myOverconstraintListener->getConflictingColor(aColor);
-            aPrs->SetConflictingConstraint(isConflicting, aColor);
-            aCustomized = true;
-          }
-        }
-      }
-    }
-    // customize sketch dimension constraint presentation
-    if (!aCustomized) {
-      std::vector<int> aColor;
-      if (isConflicting) {
-        myOverconstraintListener->getConflictingColor(aColor);
-      }
-      if (aColor.empty())
-        XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
-      if (!aColor.empty()) {
-        aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
-      }
+    std::vector<int> aColor;
+    XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
+    if (!aColor.empty()) {
+      aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
     }
   }
   // customize dimentional constrains
@@ -1056,6 +1038,48 @@ bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr the
   return aCustomized;
 }
 
+bool PartSet_Module::afterCustomisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
+                                                AISObjectPtr thePrs,
+                                                GeomCustomPrsPtr theCustomPrs)
+{
+  bool aCustomized = false;
+
+  XGUI_Workshop* aWorkshop = getWorkshop();
+  XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+  ObjectPtr anObject = aDisplayer->getObject(thePrs);
+  if (!anObject)
+    return aCustomized;
+
+  std::vector<int> aColor;
+  bool aUseCustomColor = true;
+  if (aUseCustomColor)
+    myOverconstraintListener->getCustomColor(anObject, aColor);
+  // customize sketch symbol presentation
+  Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
+  if (!anAISIO.IsNull()) {
+    if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
+      Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
+      if (!aPrs.IsNull()) {
+        aPrs->SetCustomColor(aColor);
+        aCustomized = true;
+      }
+    } else if (!Handle(SketcherPrs_Coincident)::DownCast(anAISIO).IsNull()) {
+      Handle(SketcherPrs_Coincident) aPrs = Handle(SketcherPrs_Coincident)::DownCast(anAISIO);
+      if (!aPrs.IsNull()) {
+        aPrs->SetCustomColor(aColor);
+        aCustomized = true;
+      }
+    }
+  }
+  // customize sketch dimension constraint presentation
+  if (!aCustomized) {
+    if (!aColor.empty()) { // otherwise presentation has the default color
+      aCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+    }
+  }
+  return aCustomized;
+}
+
 bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
                                      const bool theUpdateViewer)
 {
@@ -1144,14 +1168,15 @@ void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
   SessionPtr aMgr = ModelAPI_Session::get();
   QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PART_CMD");
 
+  bool hasResult = false;
+  bool hasFeature = false;
+  bool hasParameter = false;
+  bool hasCompositeOwner = false;
+  ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
+                                  hasCompositeOwner);
+
   ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
   if (aSelected == 1) {
-    bool hasResult = false;
-    bool hasFeature = false;
-    bool hasParameter = false;
-    bool hasCompositeOwner = false;
-    ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
-                                   hasCompositeOwner);
     ObjectPtr aObject = aObjects.first();
     if (aObject) {
       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
@@ -1179,10 +1204,12 @@ void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
           }
         }
       }
-
-      ResultBodyPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
-      if( aResult.get() )
-        theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD"));
+    }
+  } else {
+    if (hasFeature) {
+      myMenuMgr->action("EDIT_CMD")->setEnabled(aCurrentOp == 0);
+      theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
+      theMenu->addSeparator();
     }
   }
   bool aNotDeactivate = (aCurrentOp == 0);
@@ -1221,12 +1248,12 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
 
     SessionPtr aMgr = ModelAPI_Session::get();
     DocumentPtr aActiveDoc = aMgr->activeDocument();
-    if (aActivePartIndex.isValid())
-      aTreeView->setExpanded(aActivePartIndex, false);
+    if (myActivePartIndex.isValid())
+      aTreeView->setExpanded(myActivePartIndex, false);
     XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
-    aActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
-    if (aActivePartIndex.isValid())
-      aTreeView->setExpanded(aActivePartIndex, true);
+    myActivePartIndex = aDataModel->documentRootIndex(aActiveDoc);
+    if (myActivePartIndex.isValid())
+      aTreeView->setExpanded(myActivePartIndex, true);
 
     aLabel->setPalette(aPalet);
     aWorkshop->updateCommandStatus();
@@ -1236,7 +1263,6 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
     QObjectPtrList aObjects = aDisplayer->displayedObjects();
     bool aHidden;
     foreach(ObjectPtr aObj, aObjects) {
-      //TODO: replace by redisplay event.
       aHidden = !aObj->data() || !aObj->data()->isValid() ||
         aObj->isDisabled() || (!aObj->isDisplayed());
       if (!aHidden)
@@ -1251,12 +1277,14 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
     ObjectPtr aConstrObj;
     ObjectPtr aResultObj;
     std::set<ObjectPtr>::const_iterator aIt;
-    std::string aObjType;
+    DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
     for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
       ObjectPtr aObject = (*aIt);
-      if ((!aResultObj.get()) && aObject->groupName() == ModelAPI_ResultBody::group())
+      if ((!aResultObj.get()) && (aObject->groupName() == ModelAPI_ResultBody::group())
+          && (aObject->document() != aRootDoc))
         aResultObj = aObject;
-      if ((!aConstrObj.get()) && aObject->groupName() == ModelAPI_ResultConstruction::group())
+      if ((!aConstrObj.get()) && (aObject->groupName() == ModelAPI_ResultConstruction::group())
+          && (aObject->document() != aRootDoc))
         aConstrObj = aObject;
       if (aResultObj.get() && aConstrObj.get())
         break;
@@ -1283,7 +1311,8 @@ void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
     return;
   SessionPtr aMgr = ModelAPI_Session::get();
   if (!theIndex.isValid()) {
-    aMgr->setActiveDocument(aMgr->moduleDocument());
+    // It seems that this code is obsolete
+    //aMgr->setActiveDocument(aMgr->moduleDocument());
     return;
   }
   if (theIndex.column() != 0) // Use only first column
@@ -1307,7 +1336,7 @@ void PartSet_Module::onTreeViewDoubleClick(const QModelIndex& theIndex)
     if (aPart->partDoc() == aMgr->activeDocument()) {
       myMenuMgr->activatePartSet();
     } else {
-      aPart->activate();
+      myMenuMgr->activatePart(aPart);
     }
   }
 }
@@ -1406,6 +1435,18 @@ AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
   return anAttribute;
 }
 
+//******************************************************
+std::shared_ptr<Events_Message> PartSet_Module::reentrantMessage()
+{
+  return sketchReentranceMgr()->reentrantMessage();
+}
+
+//******************************************************
+void PartSet_Module::setReentrantPreSelection(const std::shared_ptr<Events_Message>& theMessage)
+{
+  sketchReentranceMgr()->setReentrantPreSelection(theMessage);
+}
+
 //******************************************************
 void PartSet_Module::onChoiceChanged(ModuleBase_ModelWidget* theWidget,
                                      int theIndex)