Salome HOME
Issue #1199 - Fatal error when edit parameter: do not visualize operation prs when...
authornds <nds@opencascade.com>
Fri, 15 Jan 2016 08:21:00 +0000 (11:21 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:03:04 +0000 (17:03 +0300)
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
src/XGUI/XGUI_WorkshopListener.h

index ed43e19bd2953568e6fb26e480d15dcb49e33d82..e43ccc980fd091230a4caf2f5d0de63cb2bee6f0 100755 (executable)
@@ -49,13 +49,11 @@ bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpd
   bool isModified = false;
   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
 
-  if (anOperationPrs->canActivate(theFeature)) {
-    myIsActive = true;
-    anOperationPrs->setFeature(theFeature);
-    if (theFeature.get()) {
-      displayPresentation(theUpdateViewer);
-      isModified = true;
-    }
+  myIsActive = true;
+  anOperationPrs->setFeature(theFeature);
+  if (theFeature.get()) {
+    displayPresentation(theUpdateViewer);
+    isModified = true;
   }
   return isModified;
 }
@@ -77,10 +75,11 @@ bool PartSet_CustomPrs::deactivate(const bool theUpdateViewer)
   return isModified;
 }
 
-
-void PartSet_CustomPrs::displayPresentation(const bool theUpdateViewer)
+bool PartSet_CustomPrs::displayPresentation(const bool theUpdateViewer)
 {
+  bool isModified = false;
   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
+  anOperationPrs->updateShapes();
 
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
   if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) {
@@ -89,17 +88,22 @@ void PartSet_CustomPrs::displayPresentation(const bool theUpdateViewer)
       XGUI_Workshop* aWorkshop = workshop();
       aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, theUpdateViewer);
       aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
+      isModified = true;
     }
   }
   else {
-    if (!anOperationPrs->hasShapes())
+    if (!anOperationPrs->hasShapes()) {
       erasePresentation(theUpdateViewer);
+      isModified = true;
+    }
     else {
       anOperationPrs->Redisplay();
+      isModified = true;
       if (theUpdateViewer)
         workshop()->displayer()->updateViewer();
     }
   }
+  return isModified;
 }
 
 void PartSet_CustomPrs::erasePresentation(const bool theUpdateViewer)
@@ -123,30 +127,7 @@ bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject,
 #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
   return false;
 #endif
-
-  bool isModified = false;
-  // the presentation should be recomputed if the previous AIS depend on the result
-  // [it should be hiddend] or the new AIS depend on it [it should be visualized]
-  Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
-  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
-  if (!aContext.IsNull()) {
-    if (aContext->IsDisplayed(anOperationPrs)) {
-      // if there are performance poblems, to improve them, the necessity of redisplay can be checked
-      //bool aChanged = anOperationPrs->dependOn(theObject);
-      anOperationPrs->updateShapes();
-      //aChanged = aChanged || anOperationPrs->dependOn(theObject);
-      //if (aChanged)
-      anOperationPrs->Redisplay();
-      isModified = true;
-      if (theUpdateViewer)
-        workshop()->displayer()->updateViewer();
-    }
-    else {
-      anOperationPrs->updateShapes();
-      displayPresentation(theUpdateViewer);
-    }
-  }
-  return isModified;
+  return displayPresentation(theUpdateViewer);
 }
 
 void PartSet_CustomPrs::clearPrs()
index 1d12d68029d219d00ad95fde307a685e2062b2cb..ab82997a72817eb4489eadeb2e72a21f5cba4009 100755 (executable)
@@ -74,16 +74,12 @@ private:
 
   /// Displays the internal presentation in the viewer of workshop
   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
-  void displayPresentation(const bool theUpdateViewer);
+  bool displayPresentation(const bool theUpdateViewer);
 
   /// Erases the internal presentation from the viewer of workshop
   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
   void erasePresentation(const bool theUpdateViewer);
 
-  /// Sets color, point size and width of the presentation
-  /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
-  void customizePresentation(const bool theUpdateViewer);
-
 private:
   bool myIsActive;
   ModuleBase_IWorkshop* myWorkshop; /// current workshop
index cbf29b38bb4f107303a24716daa4da3f32a7c489..af1f3ae4b972fafbe5a9d54082c816a923c5c876 100755 (executable)
@@ -43,29 +43,11 @@ PartSet_OperationPrs::PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop)
   myResultColor = ModuleBase_Tools::color("Visualization", "construction_plane_color", "0,1,0");
 }
 
-bool PartSet_OperationPrs::canActivate(const FeaturePtr& theFeature)
-{
-  bool aHasSelectionAttribute = false;
-
-  std::list<AttributePtr> anAttributes = theFeature->data()->attributes("");
-  std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
-  for (; anIt != aLast && !aHasSelectionAttribute; anIt++)
-    aHasSelectionAttribute = isSelectionAttribute(*anIt);
-
-  return aHasSelectionAttribute;
-}
-
 void PartSet_OperationPrs::setFeature(const FeaturePtr& theFeature)
 {
   myFeature = theFeature;
-  updateShapes();
 }
 
-/*bool PartSet_OperationPrs::dependOn(const ObjectPtr& theResult)
-{
-  return myFeatureShapes.contains(theResult);
-}*/
-
 void PartSet_OperationPrs::updateShapes()
 {
   myFeatureShapes.clear();
@@ -78,7 +60,27 @@ void PartSet_OperationPrs::updateShapes()
 
 bool PartSet_OperationPrs::hasShapes()
 {
-  return !myFeatureShapes.empty() || !myFeatureResults.empty();
+  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;
 }
 
 void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
@@ -326,17 +328,6 @@ bool PartSet_OperationPrs::isSelectionAttribute(const AttributePtr& theAttribute
 {
   std::string anAttrType = theAttribute->attributeType();
 
-  /// workaround: start
-  /// this is a TEMPORARY correction in order to avoid crash by parameter edit
-  /// which is reproduced only on Linux Debian.
-  /// The possible reason is an empty AIS presentation visualized in the viewer.
-  /// The best solution is to analize whether the feature has shapes/results and only
-  /// in this case visualize custom presentation and hide it as soon as they disappear.
-  bool isAttributeArgument = theAttribute->isArgument();
-  if (!isAttributeArgument)
-    return false;
-  /// workaround: end
-
   return anAttrType == ModelAPI_AttributeSelectionList::typeId() ||
          anAttrType == ModelAPI_AttributeRefList::typeId() ||
          anAttrType == ModelAPI_AttributeRefAttr::typeId() ||
index 64d92151ad5dfaebb3b741135ecb344d6aba6fc8..8bb9d36c88b6c52aafd7e231233a72b12e3efa8b 100755 (executable)
@@ -47,18 +47,10 @@ public:
   /// Constructor
   Standard_EXPORT PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop);
 
-  /// Returns true if the feature contains attributes, which has references to other features
-  /// \param theFeature a feature
-  /// \return boolean result
-  bool canActivate(const FeaturePtr& theFeature);
-
   /// Sets the operation feature. It is used in Compute method to group the feature parameter shapes
   /// theFeature a feature
   void setFeature(const FeaturePtr& theFeature);
 
-  /// Returns true if the presentation 
-  //bool dependOn(const ObjectPtr& theObject);
-
   // Recompute internal list of shaped dependent on the current feature
   void updateShapes();
 
index 457d41216fce446429020c748d1d3a158c2cc037..f9c006199f5451df6edbf880d3d93792deb599af 100755 (executable)
@@ -194,7 +194,7 @@ void XGUI_WorkshopListener::processEvent(const std::shared_ptr<Events_Message>&
   } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_OBJECT_ERROR_CHANGED)) {
     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
-    std::set<ObjectPtr> aObjects = aUpdMsg->objects();
+    std::set<ObjectPtr> anObjects = aUpdMsg->objects();
 
     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                               (workshop()->operationMgr()->currentOperation());
@@ -203,7 +203,7 @@ void XGUI_WorkshopListener::processEvent(const std::shared_ptr<Events_Message>&
       FeaturePtr aFeature = aFOperation->feature();
       if (aFeature.get()) {
         std::set<ObjectPtr>::const_iterator aIt;
-        for (aIt = aObjects.begin(); aIt != aObjects.end() && !aFeatureChanged; ++aIt) {
+        for (aIt = anObjects.begin(); aIt != anObjects.end() && !aFeatureChanged; ++aIt) {
           aFeatureChanged = ModelAPI_Feature::feature(*aIt) == aFeature;
         }
       }
@@ -231,14 +231,14 @@ void XGUI_WorkshopListener::onFeatureUpdatedMsg(
                                      const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
 {
 #ifdef DEBUG_FEATURE_UPDATED
-  std::set<ObjectPtr> aObjects = theMsg->objects();
+  std::set<ObjectPtr> anObjects = theMsg->objects();
   std::set<ObjectPtr>::const_iterator aIt;
   QStringList anInfo;
-  for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
+  for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
   }
   QString anInfoStr = anInfo.join(";\t");
-  qDebug(QString("onFeatureUpdatedMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
+  qDebug(QString("onFeatureUpdatedMsg: %1, %2").arg(anObjects.size()).arg(anInfoStr).toStdString().c_str());
 #endif
   std::set<ObjectPtr> aFeatures = theMsg->objects();
   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
@@ -266,16 +266,16 @@ void XGUI_WorkshopListener::onFeatureUpdatedMsg(
 //******************************************************
 void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
 {
-  std::set<ObjectPtr> aObjects = theMsg->objects();
+  std::set<ObjectPtr> anObjects = theMsg->objects();
   std::set<ObjectPtr>::const_iterator aIt;
 
 #ifdef DEBUG_FEATURE_REDISPLAY
   QStringList anInfo;
-  for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
+  for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
   }
   QString anInfoStr = anInfo.join(";\t");
-  qDebug(QString("onFeatureRedisplayMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
+  qDebug(QString("onFeatureRedisplayMsg: %1, %2").arg(anObjects.size()).arg(anInfoStr).toStdString().c_str());
 #endif
 
   XGUI_Workshop* aWorkshop = workshop();
@@ -283,7 +283,7 @@ void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI
   bool aFirstVisualizedBody = false;
 
   bool aRedisplayed = false;
-  for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
+  for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
     ObjectPtr aObj = (*aIt);
 
     // Hide the object if it is invalid or concealed one
@@ -355,8 +355,8 @@ void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI
       }
     }
   }
-  if (aRedisplayed) {
-    customizeCurrentObject();
+  bool isCustomized = customizeCurrentObject(anObjects, aRedisplayed);
+  if (aRedisplayed || isCustomized) {
     //VSV FitAll updated viewer by it self
     if (aFirstVisualizedBody)
       myWorkshop->viewer()->fitAll();
@@ -367,22 +367,22 @@ void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI
 //******************************************************
 void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
 {
-  std::set<ObjectPtr> aObjects = theMsg->objects();
+  std::set<ObjectPtr> anObjects = theMsg->objects();
   std::set<ObjectPtr>::const_iterator aIt;
 #ifdef DEBUG_FEATURE_CREATED
   QStringList anInfo;
-  for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
+  for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
   }
   QString anInfoStr = anInfo.join(";\t");
-  qDebug(QString("onFeatureCreatedMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
+  qDebug(QString("onFeatureCreatedMsg: %1, %2").arg(anObjects.size()).arg(anInfoStr).toStdString().c_str());
 #endif
 
   bool aFirstVisualizedBody = false;
 
   //bool aHasPart = false;
   bool aDisplayed = false;
-  for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
+  for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
     ObjectPtr anObject = *aIt;
 
 #ifdef DEBUG_RESULT_COMPSOLID
@@ -418,10 +418,11 @@ void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_O
     }
   }
 
+  bool isCustomized = customizeCurrentObject(anObjects, aDisplayed);
+
   //if (myObjectBrowser)
   //  myObjectBrowser->processEvent(theMsg);
   if (aDisplayed) {
-    customizeCurrentObject();
     //VSV FitAll updated viewer by it self
     if (aFirstVisualizedBody)
       myWorkshop->viewer()->fitAll();
@@ -561,20 +562,29 @@ bool XGUI_WorkshopListener::displayObject(ObjectPtr theObj, bool& theFirstVisual
   return aDisplayed;
 }
 
-bool XGUI_WorkshopListener::customizeCurrentObject()
+bool XGUI_WorkshopListener::customizeCurrentObject(const std::set<ObjectPtr>& theObjects,
+                                                   bool theForceRedisplay)
 {
-  bool aCustomized = false;
   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
+  FeaturePtr aCurrentFeature;
   if (anOperationMgr->hasOperation()) {
     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                       (anOperationMgr->currentOperation());
     if (aFOperation) {
-      FeaturePtr aCurrentFeature = aFOperation->feature();
-      if (aCurrentFeature.get())
-        aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
-                                           ModuleBase_IModule::CustomizeAllObjects, false);
+      aCurrentFeature = aFOperation->feature();
     }
   }
+
+  bool aCustomized = false;
+  if (aCurrentFeature.get()) {
+    // the customize presentation should be redisplayed if force redislayed is true or
+    // if a list of message objects contains the operation feature for case when
+    // the feature is hidden, but arguments of the feature are modified
+    // 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::CustomizeAllObjects, false);
+  }
   return aCustomized;
 }
 
index cf611cb264680e099968938df799dfa85ffb36c5..49199f22512379576bead7d152a36e76f726a0ee 100755 (executable)
@@ -68,8 +68,12 @@ protected:
   bool displayObject(ObjectPtr theObj, bool& theFirstVisualizedBody);
 
   /// Calls the module method of cusomize object for the feature of the current operation
+  /// Perform cusomize if the force redisplay flag is true or the list of objects contains the
+  /// current operation feature
+  /// \param theObjects a list of objects to find current operation feature if forced redisplay is false
+  /// \param theForceRedisplay a flag to customize object even always
   /// \return true if the object is modified
-  bool customizeCurrentObject();
+  bool customizeCurrentObject(const std::set<ObjectPtr>& theObjects, bool theForceRedisplay);
 
   /// Returns the workshop
   XGUI_Workshop* workshop() const;