Salome HOME
Add tools
[modules/shaper.git] / src / ModuleBase / ModuleBase_Tools.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 2deb05c..d2009ac
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_ResultParameter.h>
+#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_Tools.h>
 
 #include <GeomDataAPI_Point2D.h>
 #include <Events_Error.h>
 
+#include <Config_PropManager.h>
+
 #include <QWidget>
 #include <QLayout>
 #include <QPainter>
@@ -24,6 +28,9 @@
 
 #include <sstream>
 
+const double tolerance = 1e-7;
+
+
 namespace ModuleBase_Tools {
 
 //******************************************************************
@@ -113,6 +120,10 @@ QPixmap lighter(const QString& theIcon, const int theLighterValue)
 
 void setSpinText(ModuleBase_ParamSpinBox* theSpin, const QString& theText)
 {
+  if (theSpin->text() == theText) 
+    return;
+  // In order to avoid extra text setting because it will
+  // reset cursor position in control
   bool isBlocked = theSpin->blockSignals(true);
   theSpin->setText(theText);
   theSpin->blockSignals(isBlocked);
@@ -120,6 +131,8 @@ void setSpinText(ModuleBase_ParamSpinBox* theSpin, const QString& theText)
 
 void setSpinValue(QDoubleSpinBox* theSpin, double theValue)
 {
+  if (fabs(theSpin->value() - theValue) < tolerance)
+    return;
   bool isBlocked = theSpin->blockSignals(true);
   theSpin->setValue(theValue);
   theSpin->blockSignals(isBlocked);
@@ -127,6 +140,8 @@ void setSpinValue(QDoubleSpinBox* theSpin, double theValue)
 
 void setSpinValue(ModuleBase_ParamSpinBox* theSpin, double theValue)
 {
+  if (fabs(theSpin->value() - theValue) < tolerance)
+    return;
   bool isBlocked = theSpin->blockSignals(true);
   theSpin->setValue(theValue);
   theSpin->blockSignals(isBlocked);
@@ -149,6 +164,8 @@ QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo)
       aFeatureStr.append("[disabled]");
     if (aRes->isConcealed())
       aFeatureStr.append("[concealed]");
+    if (ModelAPI_Tools::hasSubResults(aRes))
+      aFeatureStr.append("[hasSubResults]");
 
     aFeature = ModelAPI_Feature::feature(aRes);
   }
@@ -204,6 +221,7 @@ TopAbs_ShapeEnum shapeType(const QString& theType)
     MyShapeTypes["shell"] = TopAbs_SHELL;
     MyShapeTypes["solid"] = TopAbs_SOLID;
     MyShapeTypes["solids"] = TopAbs_SOLID;
+    MyShapeTypes["objects"] = TopAbs_SHAPE;
   }
   QString aType = theType.toLower();
   if (MyShapeTypes.contains(aType))
@@ -212,11 +230,12 @@ TopAbs_ShapeEnum shapeType(const QString& theType)
   return TopAbs_SHAPE;
 }
 
-void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature, bool& hasParameter)
+void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature, bool& hasParameter, bool& hasSubFeature)
 {
   hasResult = false;
   hasFeature = false;
   hasParameter = false;
+  hasSubFeature = false;
   foreach(ObjectPtr aObj, theObjects) {
     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
@@ -225,11 +244,27 @@ void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFe
     hasResult = (aResult.get() != NULL);
     hasFeature = (aFeature.get() != NULL);
     hasParameter = (aConstruction.get() != NULL);
-    if (hasFeature && hasResult  && hasParameter)
+    if (hasFeature) 
+      hasSubFeature = (ModelAPI_Tools::compositeOwner(aFeature) != NULL);
+    if (hasFeature && hasResult  && hasParameter && hasSubFeature)
       break;
   }
 }
 
+void setDefaultDeviationCoefficient(const TopoDS_Shape& theShape,
+                                    const Handle(Prs3d_Drawer)& theDrawer)
+{
+  if (!theShape.IsNull() && theShape.ShapeType() == TopAbs_EDGE)
+    theDrawer->SetDeviationCoefficient(1.e-4);
+}
+
+Quantity_Color color(const std::string& theSection,
+                     const std::string& theName,
+                     const std::string& theDefault)
+{
+  std::vector<int> aColor = Config_PropManager::color(theSection, theName, theDefault);
+  return Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB);
+}
 
 }