Salome HOME
Merge remote-tracking branch 'remotes/origin/master' into CEA_2019
[modules/shaper.git] / src / ModuleBase / ModuleBase_Tools.cpp
index b528344ce493df558b99541aabaa011b1cdc12fd..a96e15ff07179c97dffa4719e96d4fd52423d30e 100644 (file)
@@ -82,6 +82,8 @@
 #include <QMessageBox>
 #include <QAction>
 #include <QTextCodec>
+#include <QWindow>
+#include <QScreen>
 
 #include <sstream>
 #include <string>
@@ -155,7 +157,7 @@ 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
@@ -406,13 +408,15 @@ void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFe
     hasParameter |= (aConstruction.get() != NULL);
     if (hasFeature)
       hasCompositeOwner |= (ModelAPI_Tools::compositeOwner(aFeature) != NULL);
+    else if (aResult.get())
+      hasCompositeOwner |= (ModelAPI_Tools::bodyOwner(aResult) != NULL);
 
     if (!hasResultInHistory && aResult.get()) {
       FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
       hasResultInHistory = aFeature.get() && aFeature->isInHistory();
     }
 
-    if (hasFeature && hasResult  && hasParameter && hasCompositeOwner && hasFeature)
+    if (hasFeature && hasResult  && hasParameter && hasCompositeOwner)
       break;
   }
 }
@@ -759,6 +763,7 @@ void flushUpdated(ObjectPtr theObject)
   // (for the sketch result) to start processing of the sketch in the solver.
   // TODO: these flushes should be moved in a separate method provided by Model
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_VISUAL_ATTRIBUTES));
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
 
@@ -938,7 +943,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());
   }
 
@@ -1299,6 +1304,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