Salome HOME
Issue #2998: Add help description for automatic creation of constraints
[modules/shaper.git] / src / ModuleBase / ModuleBase_Tools.cpp
index e49a994ff0fac288f86a4cd4dce494658c162234..2d6e806705cf5f35ceb4808ecab2c8dfc2fa6528 100644 (file)
@@ -40,6 +40,7 @@
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Expression.h>
+#include <ModelAPI_ResultField.h>
 #include <Events_Loop.h>
 
 #include <ModelAPI_Data.h>
@@ -81,6 +82,8 @@
 #include <QMessageBox>
 #include <QAction>
 #include <QTextCodec>
+#include <QWindow>
+#include <QScreen>
 
 #include <sstream>
 #include <string>
@@ -151,10 +154,9 @@ void activateWindow(QWidget* theWidget, const QString& theInfo)
 
 void setFocus(QWidget* theWidget, const QString& theInfo)
 {
-  activateWindow(theWidget);
   theWidget->setFocus();
   // rectangle of focus is not visible on tool button widgets
-  theWidget->repaint();
+  theWidget->update();
 #ifdef DEBUG_SET_FOCUS
   qDebug(QString("setFocus: %1").arg(theInfo).toStdString().c_str());
 #endif
@@ -397,8 +399,9 @@ void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFe
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
     FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aObj);
     ResultParameterPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aResult);
+    FieldStepPtr aStep = std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObj);
 
-    hasResult |= (aResult.get() != NULL);
+    hasResult |= ((aResult.get() != NULL) || (aStep.get() != NULL));
     hasFeature |= (aFeature.get() != NULL);
     hasFolder |= (aFolder.get() != NULL);
     hasParameter |= (aConstruction.get() != NULL);
@@ -936,7 +939,7 @@ bool askToDelete(const std::set<FeaturePtr> theFeatures,
   if (!ModelAPI_Tools::allDocumentsActivated(aNotActivatedNames)) {
     if (ModuleBase_Tools::hasModuleDocumentFeature(theFeatures))
       aNotActivatedDocWrn =
-        QObject::tr("Selected objects can be used in Part documents which are not loaded:%1.\n")
+        QObject::tr("Selected objects can be used in Part documents which are not loaded: %1.\n")
                             .arg(aNotActivatedNames.c_str());
   }
 
@@ -1128,7 +1131,7 @@ void setPointBallHighlighting(AIS_Shape* theAIS)
       aFile = std::string(anEnv) +
         FSEP + "share" + FSEP + "salome" + FSEP + "resources" + FSEP + "shaper";
     } else {
-      anEnv = getenv("OPENPARTS_ROOT_DIR");
+      anEnv = getenv("CADBUILDER_ROOT_DIR");
       if (anEnv)
         aFile = std::string(anEnv) + FSEP + "resources";
     }
@@ -1297,6 +1300,36 @@ std::string generateName(const AttributePtr& theAttribute,
   return aName;
 }
 
+bool isSameShape(const TopoDS_Shape& theShape1, const TopoDS_Shape& theShape2)
+{
+  // In case of compound we cannot rely on simple comparison method.
+  // If the compound is generated by Group feature then this compound is alwais new.
+  // So, we have to compare content of these compounds
+  if (theShape1.ShapeType() != theShape2.ShapeType())
+    return false;
+
+  if (theShape1.ShapeType() != TopAbs_COMPOUND)
+    return theShape1.IsSame(theShape2);
+
+  TopoDS_Iterator aIt1(theShape1);
+  TopoDS_Iterator aIt2(theShape2);
+
+  for (; aIt1.More() && aIt2.More(); aIt1.Next(), aIt2.Next()) {
+    if (!(aIt1.Value()).IsSame(aIt2.Value()))
+      return false;
+  }
+  return true;
+}
+
+qreal currentPixelRatio()
+{
+  QWindowList aWnds = qApp->topLevelWindows();
+  if (aWnds.size() > 0)
+    return aWnds.first()->devicePixelRatio();
+  return qApp->primaryScreen()->devicePixelRatio();
+}
+
+
 } // namespace ModuleBase_Tools