]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/ModuleBase/ModuleBase_Tools.cpp
Salome HOME
Issue #1660 Ability to change the deflection coefficient
[modules/shaper.git] / src / ModuleBase / ModuleBase_Tools.cpp
index 169f911d3a0655e8053ee26f71d6579a7953d2e4..6ca02d6acd6cea45a69c99366a96f59377920fb5 100755 (executable)
@@ -12,6 +12,7 @@
 #include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_IModule.h>
 #include <ModuleBase_IconFactory.h>
+#include <ModuleBase_ResultPrs.h>
 
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <Config_PropManager.h>
 #include <Config_Translator.h>
 
+#include <Prs3d_PointAspect.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+
+#include <Image_AlienPixMap.hxx>
+
 #include <QWidget>
 #include <QLayout>
 #include <QPainter>
 #include <sstream>
 #include <string>
 
+#ifdef WIN32
+#pragma warning(disable : 4996) // for getenv
+#endif
+
 const double tolerance = 1e-7;
 const double DEFAULT_DEVIATION_COEFFICIENT = 1.e-4;
 
@@ -79,6 +89,12 @@ const double DEFAULT_DEVIATION_COEFFICIENT = 1.e-4;
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
 #endif
 
+#ifdef WIN32
+# define FSEP "\\"
+#else
+# define FSEP "/"
+#endif
+
 namespace ModuleBase_Tools {
 
 //******************************************************************
@@ -337,6 +353,8 @@ QString getShapeTypeInfo(const int theType)
     case TopAbs_EDGE:      anInfo = "edge"; break;
     case TopAbs_VERTEX:    anInfo = "vertex"; break;
     case TopAbs_SHAPE:     anInfo = "shape"; break;
+    case ModuleBase_ResultPrs::Sel_Result:
+                           anInfo = "result_shape"; break;
     default: break;
   }
   return anInfo;
@@ -387,8 +405,9 @@ QString displayedInteractiveObjects(Handle(AIS_InteractiveContext)& theContext,
 
     if (!aShapePrs.IsNull()) {
       const TopoDS_Shape& aShape = aShapePrs->Shape();
-      if (aShape.IsNull())
-        Events_Error::throwException("An empty AIS presentation");
+      if (aShape.IsNull()) {
+        //Events_Error::throwException("An empty AIS presentation");
+      }
       else
         anInfo += QString(", shape type: %1").arg(getShapeTypeInfo(aShape.ShapeType()));
     }
@@ -448,8 +467,9 @@ QString activeOwners(Handle(AIS_InteractiveContext)& theContext, const bool theS
 
     if (!BROwnr.IsNull() && BROwnr->HasShape()) {
       const TopoDS_Shape& aShape = BROwnr->Shape();
-      if (aShape.IsNull())
-        Events_Error::throwException("An empty AIS presentation");
+      if (aShape.IsNull()) {
+        //Events_Error::throwException("An empty AIS presentation");
+      }
       else
         anInfo += QString(", shape type: %1").arg(getShapeTypeInfo(aShape.ShapeType()));
     }
@@ -508,10 +528,10 @@ void selectionInfo(Handle(AIS_InteractiveContext)& theContext, const std::string
 #endif
 }
 
-typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
+typedef QMap<QString, int> ShapeTypes;
 static ShapeTypes myShapeTypes;
 
-TopAbs_ShapeEnum shapeType(const QString& theType)
+int shapeType(const QString& theType)
 {
   if (myShapeTypes.count() == 0) {
     myShapeTypes["compound"]   = TopAbs_COMPOUND;
@@ -530,7 +550,8 @@ TopAbs_ShapeEnum shapeType(const QString& theType)
     myShapeTypes["edges"]      = TopAbs_EDGE;
     myShapeTypes["vertex"]     = TopAbs_VERTEX;
     myShapeTypes["vertices"]   = TopAbs_VERTEX;
-    myShapeTypes["objects"]    = TopAbs_SHAPE;
+    myShapeTypes["object"]     = ModuleBase_ResultPrs::Sel_Result;
+    myShapeTypes["objects"]    = ModuleBase_ResultPrs::Sel_Result;
   }
   QString aType = theType.toLower();
   if(myShapeTypes.contains(aType))
@@ -561,7 +582,7 @@ void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFe
   }
 }
 
-bool setDefaultDeviationCoefficient(std::shared_ptr<GeomAPI_Shape> theGeomShape)
+/*bool setDefaultDeviationCoefficient(std::shared_ptr<GeomAPI_Shape> theGeomShape)
 {
   if (!theGeomShape.get())
     return false;
@@ -570,9 +591,9 @@ bool setDefaultDeviationCoefficient(std::shared_ptr<GeomAPI_Shape> theGeomShape)
   GeomAPI_ShapeExplorer anExp(theGeomShape, GeomAPI_Shape::FACE);
   bool anEmpty = anExp.empty();
   return !anExp.more();
-}
+}*/
 
-void setDefaultDeviationCoefficient(const std::shared_ptr<ModelAPI_Result>& theResult,
+/*void setDefaultDeviationCoefficient(const std::shared_ptr<ModelAPI_Result>& theResult,
                                     const Handle(Prs3d_Drawer)& theDrawer)
 {
   if (!theResult.get())
@@ -590,7 +611,7 @@ void setDefaultDeviationCoefficient(const std::shared_ptr<ModelAPI_Result>& theR
   if (aUseDeviation)
     theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT);
 }
-
+*/
 void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
                                     const Handle(Prs3d_Drawer)& theDrawer)
 {
@@ -599,8 +620,21 @@ void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
 
   std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape());
   aGeomShape->setImpl(new TopoDS_Shape(theShape));
-  if (setDefaultDeviationCoefficient(aGeomShape))
-    theDrawer->SetDeviationCoefficient(DEFAULT_DEVIATION_COEFFICIENT);
+
+  // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
+  // correction of deviation for them should not influence to the application performance
+  GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE);
+  bool isConstruction = !anExp.more();
+
+  double aDeflection;
+  if (isConstruction)
+    aDeflection = Config_PropManager::real("Visualization", "construction_deflection",
+                                           ModelAPI_ResultConstruction::DEFAULT_DEFLECTION());
+  else
+    aDeflection = Config_PropManager::real("Visualization", "body_deflection",
+                                           ModelAPI_ResultBody::DEFAULT_DEFLECTION());
+
+  theDrawer->SetDeviationCoefficient(aDeflection);
 }
 
 Quantity_Color color(const std::string& theSection,
@@ -768,13 +802,14 @@ bool hasObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
   return aHasObject;
 }
 
-void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
+bool setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
                const GeomShapePtr& theShape, ModuleBase_IWorkshop* theWorkshop,
                const bool theTemporarily, const bool theCheckIfAttributeHasObject)
 {
   if (!theAttribute.get())
-    return;
+    return false;
 
+  bool isDone = true;
   std::string aType = theAttribute->attributeType();
   if (aType == ModelAPI_AttributeReference::typeId()) {
     AttributeReferencePtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
@@ -811,8 +846,12 @@ void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
   }
   else if (aType == ModelAPI_AttributeRefList::typeId()) {
     AttributeRefListPtr aRefListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
-    if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject))
-      aRefListAttr->append(theObject);
+    if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject)) {
+      if (theObject.get())
+        aRefListAttr->append(theObject);
+      else
+        isDone = false;
+    }
   }
   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
     AttributeRefAttrListPtr aRefAttrListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
@@ -823,10 +862,15 @@ void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
         aRefAttrListAttr->append(anAttribute);
     }
     else {
-      if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject))
-        aRefAttrListAttr->append(theObject);
+      if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject)) {
+        if (theObject.get())
+          aRefAttrListAttr->append(theObject);
+        else
+          isDone = false;
+      }
     }
   }
+  return isDone;
 }
 
 GeomShapePtr getShape(const AttributePtr& theAttribute, ModuleBase_IWorkshop* theWorkshop)
@@ -848,6 +892,8 @@ GeomShapePtr getShape(const AttributePtr& theAttribute, ModuleBase_IWorkshop* th
                                                                                  (theAttribute);
     aShape = aSelectAttr->value();
   }
+  else // Geom2D point processing
+    aShape = theWorkshop->module()->findShape(theAttribute);
   return aShape;
 }
 
@@ -931,7 +977,7 @@ void refsToFeatureInFeatureDocument(const ObjectPtr& theObject, std::set<Feature
 
 
 //**************************************************************
-bool isSubOfComposite(const ObjectPtr& theObject)
+/*bool isSubOfComposite(const ObjectPtr& theObject)
 {
   bool isSub = false;
   std::set<FeaturePtr> aRefFeatures;
@@ -942,10 +988,10 @@ bool isSubOfComposite(const ObjectPtr& theObject)
     isSub = isSubOfComposite(theObject, *anIt);
   }
   return isSub;
-}
+}*/
 
 //**************************************************************
-bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature)
+/*bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature)
 {
   bool isSub = false;
   CompositeFeaturePtr aComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theFeature);
@@ -961,7 +1007,7 @@ bool isSubOfComposite(const ObjectPtr& theObject, const FeaturePtr& theFeature)
     }
   }
   return isSub;
-}
+}*/
 
 //**************************************************************
 ResultPtr firstResult(const ObjectPtr& theObject)
@@ -1012,7 +1058,8 @@ bool hasModuleDocumentFeature(const std::set<FeaturePtr>& theFeatures)
 bool askToDelete(const std::set<FeaturePtr> theFeatures,
                  const std::map<FeaturePtr, std::set<FeaturePtr> >& theReferences,
                  QWidget* theParent,
-                 std::set<FeaturePtr>& theReferencesToDelete)
+                 std::set<FeaturePtr>& theReferencesToDelete,
+                 const std::string& thePrefixInfo)
 {
   QString aNotActivatedDocWrn;
   std::string aNotActivatedNames;
@@ -1091,16 +1138,18 @@ bool askToDelete(const std::set<FeaturePtr> theFeatures,
   aMessageBox.setDefaultButton(QMessageBox::No);
 
   QString aText;
+  if (!thePrefixInfo.empty())
+    aText = thePrefixInfo.c_str();
   QString aSep = ", ";
   if (!aPartFeatureNames.empty())
     aText += QString(QObject::tr("The following parts will be deleted: %1.\n")).arg(aPartFeatureNames.join(aSep));
   if (!aNotActivatedDocWrn.isEmpty())
     aText += aNotActivatedDocWrn;
   if (!anOtherFeatureNames.empty())
-    aText += QString(QObject::tr("Selected features are used in the following features: %1.\nThese features will be deleted.\n"))
+    aText += QString(QObject::tr("Features are used in the following features: %1.\nThese features will be deleted.\n"))
                      .arg(anOtherFeatureNames.join(aSep));
   if (!aParamFeatureNames.empty()) {
-    aText += QString(QObject::tr("Selected parameters are used in the following features: %1.\nThese features will be deleted.\nOr parameters could be replaced by their values.\n"))
+    aText += QString(QObject::tr("Parameters are used in the following features: %1.\nThese features will be deleted.\nOr parameters could be replaced by their values.\n"))
                      .arg(aParamFeatureNames.join(aSep));
     QPushButton *aReplaceButton = aMessageBox.addButton(QObject::tr("Replace"), QMessageBox::ActionRole);
   }
@@ -1150,6 +1199,54 @@ void translate(const std::string& theContext, std::string& theMessage)
   }
 }
 
+void setPointBallHighlighting(AIS_Shape* theAIS)
+{
+  static Handle(Image_AlienPixMap) aPixMap;
+  if(aPixMap.IsNull()) {
+    // Load icon for the presentation
+    std::string aFile;
+    char* anEnv = getenv("SHAPER_ROOT_DIR");
+    if(anEnv) {
+      aFile = std::string(anEnv) +
+        FSEP + "share" + FSEP + "salome" + FSEP + "resources" + FSEP + "shaper";
+    } else {
+      anEnv = getenv("OPENPARTS_ROOT_DIR");
+      if (anEnv)
+        aFile = std::string(anEnv) + FSEP + "resources";
+    }
+
+    aFile += FSEP;
+    static const std::string aMarkerName = "marker_dot.png";
+    aFile += aMarkerName;
+    aPixMap = new Image_AlienPixMap();
+    if(!aPixMap->Load(aFile.c_str())) {
+      // The icon for constraint is not found
+      static const std::string aMsg = "Error: Point market not found by path: \"" + aFile + "\". Falling back.";
+      //Events_InfoMessage("ModuleBase_Tools::setPointBallHighlighting", aMsg).send();
+    }
+  }
+
+  Handle(Graphic3d_AspectMarker3d) anAspect;
+  Handle(Prs3d_Drawer) aDrawer = theAIS->HilightAttributes();
+  if(aDrawer->HasOwnPointAspect()) {
+    Handle(Prs3d_PointAspect) aPntAspect = aDrawer->PointAspect();
+    if(aPixMap->IsEmpty()) {
+      anAspect = aPntAspect->Aspect();
+      anAspect->SetType(Aspect_TOM_BALL);
+    } else {
+      if(aPixMap->Format() == Image_PixMap::ImgGray) {
+        aPixMap->SetFormat (Image_PixMap::ImgAlpha);
+      } else if(aPixMap->Format() == Image_PixMap::ImgGrayF) {
+        aPixMap->SetFormat (Image_PixMap::ImgAlphaF);
+      }
+      anAspect = new Graphic3d_AspectMarker3d(aPixMap);
+      aPntAspect->SetAspect(anAspect);
+    }
+    aDrawer->SetPointAspect(aPntAspect);
+    theAIS->SetHilightAttributes(aDrawer);
+  }
+}
+
 } // namespace ModuleBase_Tools