Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
index 5898c252db08c15615fadd2313cbaf7cc2f004c2..2b92c351a5ec2fdf8a88d31fd0c77168050d70cb 100644 (file)
 #include <ModuleBase_FilterFactory.h>
 #include <ModuleBase_FilterLinearEdge.h>
 #include <ModuleBase_FilterFace.h>
-
+#include <ModuleBase_FilterMulti.h>
+#include <ModuleBase_FilterCustom.h>
+#include <ModuleBase_FilterNoConsructionSubShapes.h>
 
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Session.h>
+#include <ModelAPI_ShapeValidator.h>
 
 #include <GeomDataAPI_Point2D.h>
 #include <GeomDataAPI_Point.h>
@@ -49,6 +52,7 @@
 //#include <SketchPlugin_ConstraintRigid.h>
 
 #include <Events_Loop.h>
+#include <Config_PropManager.h>
 
 #include <StdSelect_TypeOfFace.hxx>
 #include <TopoDS_Vertex.hxx>
@@ -113,6 +117,8 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
   aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
+  aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
+  aFactory->registerValidator("PartSet_SketchValidator", new PartSet_SketchValidator);
 }
 
 void PartSet_Module::registerFilters()
@@ -123,12 +129,31 @@ void PartSet_Module::registerFilters()
 
   aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
   aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
+  aFactory->registerFilter("MultiFilter", new ModuleBase_FilterMulti);
+  Handle(SelectMgr_Filter) aSelectFilter = new ModuleBase_FilterNoConsructionSubShapes(workshop());
+  aFactory->registerFilter("NoConstructionSubShapesFilter",
+            new ModuleBase_FilterCustom(aSelectFilter));
+}
+
+void PartSet_Module::registerProperties()
+{
+  Config_PropManager::registerProp("Sketch planes", "planes_size", "Size", Config_Prop::Double,
+                                   PLANE_SIZE);
+  Config_PropManager::registerProp("Sketch planes", "planes_thickness", "Thickness",
+                                   Config_Prop::Integer, SKETCH_WIDTH);
 }
 
 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation) 
 {
   if (theOperation->isEditOperation())
     return;
+  // the selection is cleared after commit the create operation
+  // in order to do not use the same selected objects in the restarted operation
+  // for common behaviour, the selection is cleared even if the operation is not restarted
+  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+  if (!aContext.IsNull())
+    aContext->ClearSelected();
+
   /// Restart sketcher operations automatically
   FeaturePtr aFeature = theOperation->feature();
   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
@@ -137,6 +162,7 @@ void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation)
                      myRestartingMode == RM_EmptyFeatureUsed)) {
     myLastOperationId = theOperation->id();
     myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
+    
     launchOperation(myLastOperationId);
   }
   breakOperationSequence();
@@ -172,6 +198,39 @@ void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
   myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter);
 }
 
+bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const
+{
+  bool aCanDisplay = false;
+  CompositeFeaturePtr aSketchFeature = mySketchMgr->activeSketch();
+  if (aSketchFeature.get() != NULL) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+
+    // MPV: the second and third conditions to avoid crash on exit for application
+    if (aFeature.get() != NULL && aFeature->data().get() && aFeature->data()->isValid()) {
+      if (aFeature == aSketchFeature) {
+        aCanDisplay = false;
+      }
+      else if (aSketchFeature.get() && aSketchFeature->data().get() &&
+               aSketchFeature->data()->isValid()) {
+        for (int i = 0; i < aSketchFeature->numberOfSubs() && !aCanDisplay; i++) {
+          FeaturePtr aSubFeature = aSketchFeature->subFeature(i);
+          std::list<ResultPtr> aResults = aSubFeature->results();
+          std::list<ResultPtr>::const_iterator aIt;
+          for (aIt = aResults.begin(); aIt != aResults.end() && !aCanDisplay; ++aIt) {
+            if (theObject == (*aIt))
+              aCanDisplay = true;
+          }
+          if (aSubFeature == theObject)
+            aCanDisplay = true;
+        }
+      }
+    }
+  }
+  else {
+    aCanDisplay = ModuleBase_IModule::canDisplayObject(theObject);
+  }
+  return aCanDisplay;
+}
 
 void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
 {
@@ -197,13 +256,14 @@ void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
           aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
           PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(), 
             aWgt->attributeID(), aPoint->x(), aPoint->y());
-          theOperation->propertyPanel()->activateNextWidget(aPnt2dWgt);
+          aPanel->activateNextWidget(aPnt2dWgt);
         }
       }
     }
   } else {
     // Start editing constraint
     if (theOperation->isEditOperation()) {
+      // TODO: #391 - to be removed
       std::string aId = theOperation->id().toStdString();
       if (PartSet_SketcherMgr::sketchOperationIdList().contains(QString(aId.c_str()))) {
         if ((aId == SketchPlugin_ConstraintRadius::ID()) ||
@@ -254,17 +314,9 @@ void PartSet_Module::onSelectionChanged()
         }
       }
     }
-  } else if (mySketchMgr->sketchOperationIdList().contains(aOperation->id()) && 
-    aOperation->isEditOperation()) {
-    // if this is sketch operation in edit mode
-
-      ModuleBase_ISelection* aSelect = myWorkshop->selection();
-      //aSelect->selectedShapes();
-  }
+  } 
 }
 
-      // after movement the solver will call the update event: optimization
-
 void PartSet_Module::onKeyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent)
 {
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
@@ -311,7 +363,7 @@ void PartSet_Module::onNoMoreWidgets()
   }
 }
 
-void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape)
+void PartSet_Module::onVertexSelected()
 {
   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
   if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
@@ -343,8 +395,7 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget*
     aWgt->setWorkshop(aWorkshop);
     aWgt->setSketch(mySketchMgr->activeSketch());
 
-    connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)), 
-      this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&)));
+    connect(aWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
 
     theModelWidgets.append(aWgt);
     return aWgt->getControl();