Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[modules/shaper.git] / src / ModuleBase / ModuleBase_Tools.cpp
index 0f57b4c7b7fedc812fa84c3cc465d9d369d6205f..6639a548af29b5a294a5a29f05ff89e3db655e71 100644 (file)
@@ -1,12 +1,19 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        ModuleBase_Tools.cpp
 // Created:     11 July 2014
 // Author:      Vitaly Smetannikov
 
 #include "ModuleBase_Tools.h"
+
+#include <ModelAPI_Result.h>
+#include <ModelAPI_Data.h>
+
 #include <QWidget>
 #include <QLayout>
 #include <QPainter>
 #include <QBitmap>
+#include <QDoubleSpinBox>
 
 namespace ModuleBase_Tools {
 
@@ -25,7 +32,7 @@ void adjustMargins(QLayout* theLayout)
 {
   if(!theLayout)
     return;
-  theLayout->setContentsMargins(2, 5, 5, 2);
+  theLayout->setContentsMargins(2, 5, 2, 5);
   theLayout->setSpacing(4);
 }
 
@@ -44,8 +51,7 @@ void zeroMargins(QLayout* theLayout)
   theLayout->setSpacing(5);
 }
 
-QPixmap composite(const QString& theAdditionalIcon, const int theXShift,
-                  const int theYShift, const QString& theIcon)
+QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon)
 {
   QImage anIcon(theIcon);
   QImage anAditional(theAdditionalIcon);
@@ -59,12 +65,12 @@ QPixmap composite(const QString& theAdditionalIcon, const int theXShift,
   int aWidth = anIcon.width();
   int aHeight = anIcon.height();
 
-  int aStartWidthPos = aWidth-anAddWidth-1;
-  int aStartHeightPos = aHeight-anAddHeight-1;
+  int aStartWidthPos = aWidth - anAddWidth - 1;
+  int aStartHeightPos = aHeight - anAddHeight - 1;
 
-  for (int i = 0; i < anAddWidth; i++)
+  for (int i = 0; i < anAddWidth && i + aStartWidthPos < aWidth; i++)
   {
-    for (int j = 0; j < anAddHeight; j++)
+    for (int j = 0; j < anAddHeight && j + aStartHeightPos < aHeight; j++)
     {
       if (qAlpha(anAditional.pixel(i, j)) > 0)
         anIcon.setPixel(i + aStartWidthPos, j + aStartHeightPos, anAditional.pixel(i, j));
@@ -96,6 +102,30 @@ QPixmap lighter(const QString& theIcon, const int theLighterValue)
   return QPixmap::fromImage(aResult);
 }
 
+void setSpinValue(QDoubleSpinBox* theSpin, double theValue)
+{
+  bool isBlocked = theSpin->blockSignals(true);
+  theSpin->setValue(theValue);
+  theSpin->blockSignals(isBlocked);
+}
+
+QString objectInfo(const ObjectPtr& theObj)
+{
+  ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
+  QString aFeatureStr = "feature";
+  if(aRes.get()) {
+    aFeatureStr.append("(Result)");
+    aFeature = ModelAPI_Feature::feature(aRes);
+  }
+  if (aFeature.get()) {
+    aFeatureStr.append(QString(": %1").arg(aFeature->getKind().c_str()).toStdString().c_str());
+    if (aFeature->data().get() && aFeature->data()->isValid())
+      aFeatureStr.append(QString("(name=%1)").arg(aFeature->data()->name().c_str()).toStdString().c_str());
+  }
+  return aFeatureStr;
+}
+
 }