]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Imrove multi-selector control to provide items multi-selection. Preferences color...
authornds <nds@opencascade.com>
Fri, 15 Jan 2016 17:29:51 +0000 (20:29 +0300)
committernds <nds@opencascade.com>
Fri, 15 Jan 2016 17:29:51 +0000 (20:29 +0300)
src/ModuleBase/ModuleBase_IModule.h
src/PartSet/PartSet_CustomPrs.cpp
src/PartSet/PartSet_CustomPrs.h
src/PartSet/PartSet_OperationPrs.cpp
src/PartSet/PartSet_OperationPrs.h
src/XGUI/XGUI_WorkshopListener.cpp

index 55a0e8b5cc8dab94ca88742a212ff2e0d80633f5..94b2ff98c822708cd91fb90aacbf90f41c7d6e20 100755 (executable)
@@ -34,8 +34,9 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
  public:\r
   /// enumeration to know which objects should be customized\r
   enum ModuleBase_CustomizeFlag {\r
-    CustomizeDependedAndResults = 0x00000000,\r
-    CustomizeHighlightedObjects = 0x00000001\r
+    CustomizeArguments = 0, /// references of other objects referenced to the current feature\r
+    CustomizeResults, /// results of the current feature\r
+    CustomizeHighlightedObjects /// highlighted objects of the active widget\r
   };\r
 \r
    /// Constructor\r
index b466171c3c3f0e7a93f2c2f67caaea68ca2cb5ca..54298f76d26bac7ab30faf396e433f216f7c93b8 100755 (executable)
 //#define DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
 
 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
-  : myWorkshop(theWorkshop), myIsActive(false)
+  : myWorkshop(theWorkshop), myIsActive(false), myFeature(FeaturePtr())
 {
-  initPresentation(ModuleBase_IModule::CustomizeDependedAndResults);
+  initPresentation(ModuleBase_IModule::CustomizeArguments);
+  initPresentation(ModuleBase_IModule::CustomizeResults);
   initPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
 }
 
@@ -43,13 +44,12 @@ bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpd
 #endif
 
   myIsActive = true;
-
+  myFeature = theFeature;
 
   bool isModified = false;
-  getPresentation(ModuleBase_IModule::CustomizeDependedAndResults)->setFeature(theFeature);
-  getPresentation(ModuleBase_IModule::CustomizeHighlightedObjects)->setFeature(theFeature);
   if (theFeature.get()) {
-    displayPresentation(ModuleBase_IModule::CustomizeDependedAndResults, theUpdateViewer);
+    displayPresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer);
+    displayPresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer);
     displayPresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer);
     isModified = true;
   }
@@ -61,37 +61,47 @@ bool PartSet_CustomPrs::deactivate(const bool theUpdateViewer)
   myIsActive = false;
   bool isModified = false;
 
-  getPresentation(ModuleBase_IModule::CustomizeDependedAndResults)->setFeature(FeaturePtr());
-  getPresentation(ModuleBase_IModule::CustomizeHighlightedObjects)->setFeature(FeaturePtr());
-
-  erasePresentation(ModuleBase_IModule::CustomizeDependedAndResults, theUpdateViewer);
+  erasePresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer);
+  erasePresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer);
   erasePresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer);
   isModified = true;
 
   return isModified;
 }
 
-bool PartSet_CustomPrs::displayPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
-                                            const bool theUpdateViewer)
+bool PartSet_CustomPrs::displayPresentation(
+                                  const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+                                  const bool theUpdateViewer)
 {
   bool isModified = false;
+
+  // update the AIS objects content
   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag);
-  if (theFlag == ModuleBase_IModule::CustomizeDependedAndResults) {
-    PartSet_OperationPrs::getFeatureShapes(anOperationPrs->getFeature(), myWorkshop,
-                                           anOperationPrs->featureShapes());
-    anOperationPrs->updateShapes();
-  }
-  else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) {
-    PartSet_OperationPrs::getHighlightedShapes(myWorkshop, anOperationPrs->featureShapes());
+  // do nothing if the feature can not be displayed [is moved from presentation, to be checked]
+  if (!myFeature.get() || !myWorkshop->module()->canDisplayObject(myFeature))
+    return isModified;
+
+  switch (theFlag) {
+    case ModuleBase_IModule::CustomizeArguments:
+      PartSet_OperationPrs::getFeatureShapes(myFeature, myWorkshop, anOperationPrs->featureShapes());
+      break;
+    case ModuleBase_IModule::CustomizeResults:
+      PartSet_OperationPrs::getResultShapes(myFeature, myWorkshop, anOperationPrs->featureShapes());
+      break;
+    case ModuleBase_IModule::CustomizeHighlightedObjects:
+      PartSet_OperationPrs::getHighlightedShapes(myWorkshop, anOperationPrs->featureShapes());
+      break;
+    default:
+      return isModified;
   }
 
+  // redisplay AIS objects
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
   if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) {
     if (anOperationPrs->hasShapes()) {
       // set color here because it can be changed in preferences
-      Quantity_Color aShapeColor, aResultColor;
-      getAISColors(theFlag, aShapeColor, aResultColor);
-      anOperationPrs->setColors(aShapeColor, aResultColor);
+      Quantity_Color aShapeColor = getShapeColor(theFlag);
+      anOperationPrs->setShapeColor(aShapeColor);
 
       PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
       XGUI_Workshop* aWorkshop = workshop();
@@ -157,7 +167,8 @@ bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject,
 
 void PartSet_CustomPrs::clearPrs()
 {
-  clearPresentation(ModuleBase_IModule::CustomizeDependedAndResults);
+  clearPresentation(ModuleBase_IModule::CustomizeArguments);
+  clearPresentation(ModuleBase_IModule::CustomizeResults);
   clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
 }
 
@@ -166,33 +177,39 @@ void PartSet_CustomPrs::initPresentation(const ModuleBase_IModule::ModuleBase_Cu
   AISObjectPtr anOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
   Handle(PartSet_OperationPrs) anAISPrs = new PartSet_OperationPrs(myWorkshop);
   anOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
-  if (theFlag == ModuleBase_IModule::CustomizeDependedAndResults) {
+  if (theFlag == ModuleBase_IModule::CustomizeArguments ||
+      theFlag == ModuleBase_IModule::CustomizeResults) {
     anOperationPrs->setPointMarker(5, 2.);
     anOperationPrs->setWidth(1);
   }
-  else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) {
+  else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects)
     anAISPrs->useAISWidth();
-  }
 
   if (anOperationPrs.get())
     myPresentations[theFlag] = anOperationPrs;
 }
 
-void PartSet_CustomPrs::getAISColors(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
-                                     Quantity_Color& theShapeColor, Quantity_Color& theResultColor)
+Quantity_Color PartSet_CustomPrs::getShapeColor(
+                                  const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
 {
-  if (theFlag == ModuleBase_IModule::CustomizeDependedAndResults) {
-    theShapeColor = ModuleBase_Tools::color("Visualization", "operation_parameter_color",
-                                            OPERATION_PARAMETER_COLOR());
-    theResultColor = ModuleBase_Tools::color("Visualization", "operation_result_color",
-                                             OPERATION_RESULT_COLOR());
-  }
-  else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) {
-    theShapeColor = ModuleBase_Tools::color("Visualization", "operation_highlight_color",
-                                            OPERATION_HIGHLIGHT_COLOR());
-    theResultColor = ModuleBase_Tools::color("Visualization", "operation_result_color",
-                                             OPERATION_RESULT_COLOR());
+  Quantity_Color aColor;
+  switch(theFlag) {
+    case ModuleBase_IModule::CustomizeArguments:
+      aColor = ModuleBase_Tools::color("Visualization", "operation_parameter_color",
+                                       OPERATION_PARAMETER_COLOR());
+    break;
+    case ModuleBase_IModule::CustomizeResults:
+      aColor = ModuleBase_Tools::color("Visualization", "operation_result_color",
+                                       OPERATION_RESULT_COLOR());
+    break;
+    case ModuleBase_IModule::CustomizeHighlightedObjects:
+      aColor = ModuleBase_Tools::color("Visualization", "operation_highlight_color",
+                                       OPERATION_HIGHLIGHT_COLOR());
+    break;
+    default:
+    break;
   }
+  return aColor;
 }
 
 XGUI_Workshop* PartSet_CustomPrs::workshop() const
index 1785818b9228d0b7520c34d586bb20367f864d18..8a27f041c5dba2908e666480a6e1ef3104995561 100755 (executable)
@@ -106,15 +106,14 @@ private:
   /// \param theFlag an object AIS presentation type
   void clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
 
-  /// Returns presentation colors according to the flag
+  /// Returns presentation color according to the flag
   /// \param theFlag an object AIS presentation type
-  /// \param theShapeColor a color for shapes
-  /// \param theShapeColor a color for results
-  void getAISColors(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
-                    Quantity_Color& theShapeColor, Quantity_Color& theResultColor);
+  /// \return theShapeColor a color
+  Quantity_Color getShapeColor(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
 
 private:
-  bool myIsActive;
+  bool myIsActive; /// State whether the presentation is activated/deactivated
+  FeaturePtr myFeature; /// Reference to a feature object
   ModuleBase_IWorkshop* myWorkshop; /// current workshop
   /// map of presentation type to AIS object
   QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, AISObjectPtr> myPresentations;
index 6858e0a143e3134b1985a17b915b26c9658c74fe..22b5ec243ad9388d96c7d3ef1897919a4a6550a9 100755 (executable)
 
 #include <QList>
 
+static const int AIS_DEFAULT_WIDTH = 2;
+
 IMPLEMENT_STANDARD_HANDLE(PartSet_OperationPrs, ViewerData_AISShape);
 IMPLEMENT_STANDARD_RTTIEXT(PartSet_OperationPrs, ViewerData_AISShape);
 
 PartSet_OperationPrs::PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop)
-: ViewerData_AISShape(TopoDS_Shape()), myFeature(FeaturePtr()), myWorkshop(theWorkshop),
- myUseAISWidth(false)
-{
-  myShapeColor = ModuleBase_Tools::color("Visualization", "construction_plane_color", "1,1,0");
-  myResultColor = ModuleBase_Tools::color("Visualization", "construction_plane_color", "0,1,0");
-}
-
-void PartSet_OperationPrs::setFeature(const FeaturePtr& theFeature)
-{
-  myFeature = theFeature;
-}
-
-void PartSet_OperationPrs::updateShapes()
+: ViewerData_AISShape(TopoDS_Shape()), myWorkshop(theWorkshop), myUseAISWidth(false)
 {
-  myFeatureResults.clear();
-  if (myFeature)
-    myFeatureResults = myFeature->results();
+  myShapeColor = Quantity_Color(1, 1, 1, Quantity_TOC_RGB);
 }
 
 bool PartSet_OperationPrs::hasShapes()
 {
-  bool aHasShapes = !myFeatureShapes.empty();
-  
-  // find a result which contains a shape
-  if (!aHasShapes && !myFeatureResults.empty()) {
-    std::list<ResultPtr>::const_iterator aRIt = myFeatureResults.begin(),
-                                         aRLast = myFeatureResults.end();
-    XGUI_Displayer* aDisplayer = workshop()->displayer();
-    for (; aRIt != aRLast; aRIt++) {
-      ResultPtr aResult = *aRIt;
-      if (!isVisible(aDisplayer, aResult))
-        continue;
-      GeomShapePtr aGeomShape = aResult->shape();
-      if (!aGeomShape.get())
-        continue;
-      TopoDS_Shape aShape = aGeomShape->impl<TopoDS_Shape>();
-      if (!aShape.IsNull())
-        aHasShapes = true;
-    }
-  }
-
-  return aHasShapes;
+  return !myFeatureShapes.empty();
 }
 
-void PartSet_OperationPrs::setColors(const Quantity_Color& theShapeColor, const Quantity_Color& theResultColor)
+void PartSet_OperationPrs::setShapeColor(const Quantity_Color& theColor)
 {
-  myShapeColor = theShapeColor;
-  myResultColor = theResultColor;
+  myShapeColor = theColor;
 }
 
 void PartSet_OperationPrs::useAISWidth()
@@ -96,17 +63,10 @@ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
                                    const Handle(Prs3d_Presentation)& thePresentation, 
                                    const Standard_Integer theMode)
 {
-  if (!hasShapes())
-    return;
-  // when the feature can not be visualized in the module, the operation preview should not
-  // be visualized also
-  if (!myWorkshop->module()->canDisplayObject(myFeature))
-    return;
-
   SetColor(myShapeColor);
   thePresentation->Clear();
-  XGUI_Displayer* aDisplayer = workshop()->displayer();
 
+  XGUI_Displayer* aDisplayer = workshop(myWorkshop)->displayer();
   Handle(Prs3d_Drawer) aDrawer = Attributes();
 
   // create presentations on the base of the shapes
@@ -130,38 +90,20 @@ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t
         AISObjectPtr anAISPtr = aDisplayer->getAISObject(anObject);
         if (anAISPtr.get()) {
           Handle(AIS_InteractiveObject) anIO = anAISPtr->impl<Handle(AIS_InteractiveObject)>();
-          if (!anIO.IsNull())
-            setWidth(aDrawer, anIO->Width());
+          if (!anIO.IsNull()) {
+            int aWidth = anIO->Width();
+            /// workaround for zero width. Else, there will be a crash
+            if (aWidth == 0) { // width returns of TSolid shape is zero
+              bool isDisplayed = !anIO->GetContext().IsNull();
+              aWidth = AIS_DEFAULT_WIDTH;// default width value
+            }
+            setWidth(aDrawer, aWidth);
+          }
         }
       }
       StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer);
     }
   }
-
-  // create presentations on the base of the results
-  SetColor(myResultColor);
-  std::list<ResultPtr>::const_iterator aRIt = myFeatureResults.begin(),
-                                       aRLast = myFeatureResults.end();
-  for (; aRIt != aRLast; aRIt++) {
-    ResultPtr aResult = *aRIt;
-    if (!isVisible(aDisplayer, aResult))
-      continue;
-    GeomShapePtr aGeomShape = aResult->shape();
-    if (!aGeomShape.get())
-      continue;
-    TopoDS_Shape aShape = aGeomShape->impl<TopoDS_Shape>();
-    // change deviation coefficient to provide more precise circle
-    ModuleBase_Tools::setDefaultDeviationCoefficient(aShape, aDrawer);
-    StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer);
-  }
-  QList<ModuleBase_ViewerPrs> aValues;
-  ModuleBase_IPropertyPanel* aPanel = myWorkshop->propertyPanel();
-  if (aPanel) {
-    ModuleBase_ModelWidget* aWidget = aPanel->activeWidget();
-    if (aWidget) {
-      aWidget->getHighlighted(aValues);
-    }
-  }
 }
 
 void PartSet_OperationPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
@@ -311,6 +253,38 @@ void PartSet_OperationPrs::getFeatureShapes(const FeaturePtr& theFeature,
   }
 }
 
+void PartSet_OperationPrs::getResultShapes(const FeaturePtr& theFeature,
+                                           ModuleBase_IWorkshop* theWorkshop,
+                                           QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes)
+{
+  theObjectShapes.clear();
+
+  if (!theFeature.get())
+    return;
+
+  XGUI_Displayer* aDisplayer = workshop(theWorkshop)->displayer();
+
+  std::list<ResultPtr> aFeatureResults = theFeature->results();
+  std::list<ResultPtr>::const_iterator aRIt = aFeatureResults.begin(),
+                                       aRLast = aFeatureResults.end();
+  for (; aRIt != aRLast; aRIt++) {
+    ResultPtr aResult = *aRIt;
+    if (!isVisible(aDisplayer, aResult))
+      continue;
+    GeomShapePtr aGeomShape = aResult->shape();
+    if (!aGeomShape.get())
+      continue;
+
+    if (theObjectShapes.contains(aResult))
+      theObjectShapes[aResult].append(aGeomShape);
+    else {
+      QList<GeomShapePtr> aShapes;
+      aShapes.append(aGeomShape);
+      theObjectShapes[aResult] = aShapes;
+    }
+  }
+}
+
 void PartSet_OperationPrs::getHighlightedShapes(ModuleBase_IWorkshop* theWorkshop,
                                                 QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes)
 {
@@ -368,8 +342,8 @@ bool PartSet_OperationPrs::isSelectionAttribute(const AttributePtr& theAttribute
          anAttrType == ModelAPI_AttributeReference::typeId();
 }
 
-XGUI_Workshop* PartSet_OperationPrs::workshop() const
+XGUI_Workshop* PartSet_OperationPrs::workshop(ModuleBase_IWorkshop* theWorkshop)
 {
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
   return aConnector->workshop();
 }
index 89d2c252ed795adcab9a8ae1a817b510a775e9ed..bf1e5a2bc6bda3cf0650d26b912387947bf6480e 100755 (executable)
@@ -47,20 +47,12 @@ public:
   /// Constructor
   Standard_EXPORT PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop);
 
-  /// Sets the operation feature. It is used in Compute method to group the feature parameter shapes
-  /// theFeature a feature
-  void setFeature(const FeaturePtr& theFeature);
-
-  // Recompute internal list of shaped dependent on the current feature
-  void updateShapes();
-
   /// Returns true if the feature contains shapes or results
   bool hasShapes();
 
   /// Sets the colors for the presentation compute
-  /// \param theShapeColor an argument shapes color
-  /// \param theResultColor a color for operation result
-  void setColors(const Quantity_Color& theShapeColor, const Quantity_Color& theResultColor);
+  /// \param theColor an argument shapes color
+  void setShapeColor(const Quantity_Color& theColor);
 
   /// Switch on using of the AIS presentation with of the shape object increased on the delta
   void useAISWidth();
@@ -78,9 +70,6 @@ protected:
                                                 const Standard_Integer aMode) ;
 
 protected:
-  /// Reference to a feature object
-  FeaturePtr getFeature() { return myFeature; }
-
   /// Returns map of feature shapes to be able to fill it outside this class, e.g. in friend
   /// \return a map of object to shape
   QMap<ObjectPtr, QList<GeomShapePtr> >& featureShapes() { return myFeatureShapes; }
@@ -91,7 +80,7 @@ private:
   /// \param theDisplayer a displayer
   /// \param theObject an object
   /// \return a boolean value
-  bool isVisible(XGUI_Displayer* theDislayer, const ObjectPtr& theObject);
+  static bool isVisible(XGUI_Displayer* theDislayer, const ObjectPtr& theObject);
 
   /// Fills the map by the feature object and shapes, which should be visuaziled
   /// Gets feature attributes, collect objects to whom the attributes refer
@@ -103,6 +92,16 @@ private:
                                ModuleBase_IWorkshop* theWorkshop,
                                QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes);
 
+  /// Fills the map by the feature object and shapes, which should be visuaziled
+  /// Gets feature attributes, collect objects to whom the attributes refer
+  /// \param theFeature a current feature
+  /// \param theWorkshop a current workshop
+  /// \param theObjectShapes an output map
+  /// \param theObjectShape an output map of objects
+  static void getResultShapes(const FeaturePtr& theFeature,
+                              ModuleBase_IWorkshop* theWorkshop,
+                              QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes);
+
   /// Fills the map by the feature object and shapes, which should be visuaziled
   /// Gets the active widget, obtain the highlighted presentations if it has such and
   /// fill map by object and shapes
@@ -117,18 +116,15 @@ private:
   static bool isSelectionAttribute(const AttributePtr& theAttribute);
 
   /// Converts the current workshop to XGUI workshop
+  /// \param theWorkshop an interface workshop
   /// \return a workshop instance
-  XGUI_Workshop* workshop() const;
+  static XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop);
 
 private:
-  ModuleBase_IWorkshop* myWorkshop;
-  FeaturePtr myFeature; /// Reference to a feature object
   QMap<ObjectPtr, QList<GeomShapePtr> > myFeatureShapes; /// visualized shapes
-  std::list<ResultPtr> myFeatureResults; /// visualized feature results
 
+  ModuleBase_IWorkshop* myWorkshop; /// current workshop
   Quantity_Color myShapeColor; /// color of feature depended shapes
-  Quantity_Color myResultColor; /// color of feature result
-
   bool myUseAISWidth; /// flag if the width of a shape object should be used for the shape visualization
 
   friend class PartSet_CustomPrs;
index d8934f2da7c14d455a1122de8a410ca25d40b953..c87f0aa3d68473a9d6358ea89859405f04cf6b18 100755 (executable)
@@ -583,7 +583,9 @@ bool XGUI_WorkshopListener::customizeCurrentObject(const std::set<ObjectPtr>& th
     // e.g. extrusion is hidden(h=0) but sketch is chosen
     if (theForceRedisplay || theObjects.find(aCurrentFeature) != theObjects.end()) {
       aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
-                                           ModuleBase_IModule::CustomizeDependedAndResults, false);
+                                           ModuleBase_IModule::CustomizeArguments, false);
+      aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
+                                           ModuleBase_IModule::CustomizeResults, false);
       aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
                                            ModuleBase_IModule::CustomizeHighlightedObjects, false);
     }