Salome HOME
Hide "by general equation" case for plane creation
[modules/shaper.git] / src / ModuleBase / ModuleBase_Tools.cpp
index 8c0471d9503f8b3f5cfee81a9c47754f2f151740..6639a548af29b5a294a5a29f05ff89e3db655e71 100644 (file)
+// 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_ResultBody.h>
-#include <ModelAPI_ResultConstruction.h>
-#include <ModelAPI_Document.h>
 
-namespace ModuleBase_Tools
-{
+#include <ModelAPI_Result.h>
+#include <ModelAPI_Data.h>
+
+#include <QWidget>
+#include <QLayout>
+#include <QPainter>
+#include <QBitmap>
+#include <QDoubleSpinBox>
+
+namespace ModuleBase_Tools {
+
+//******************************************************************
 
 //******************************************************************
-boost::shared_ptr<GeomAPI_Shape> shape(ResultPtr theResult)
+
+void adjustMargins(QWidget* theWidget)
+{
+  if(!theWidget)
+    return;
+  adjustMargins(theWidget->layout());
+}
+
+void adjustMargins(QLayout* theLayout)
 {
-  ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
-  if (aBody)
-    return aBody->shape();
+  if(!theLayout)
+    return;
+  theLayout->setContentsMargins(2, 5, 2, 5);
+  theLayout->setSpacing(4);
+}
 
-  ResultConstructionPtr aConstruct = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theResult);
-  if (aConstruct)
-    return aConstruct->shape();
+void zeroMargins(QWidget* theWidget)
+{
+  if(!theWidget)
+    return;
+  zeroMargins(theWidget->layout());
+}
 
-  return boost::shared_ptr<GeomAPI_Shape>();
+void zeroMargins(QLayout* theLayout)
+{
+  if(!theLayout)
+    return;
+  theLayout->setContentsMargins(0, 0, 0, 0);
+  theLayout->setSpacing(5);
 }
 
-//******************************************************************
-FeaturePtr feature(ObjectPtr theObject)
-{
-  FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
-  if (!aFeature) {
-    ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-    if (aResult) {
-      PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
-      DocumentPtr aDoc = aMgr->rootDocument();
-      return aDoc->feature(aResult);
+QPixmap composite(const QString& theAdditionalIcon, const QString& theIcon)
+{
+  QImage anIcon(theIcon);
+  QImage anAditional(theAdditionalIcon);
+
+  if (anIcon.isNull())
+    return QPixmap();
+
+  int anAddWidth = anAditional.width();
+  int anAddHeight = anAditional.height();
+
+  int aWidth = anIcon.width();
+  int aHeight = anIcon.height();
+
+  int aStartWidthPos = aWidth - anAddWidth - 1;
+  int aStartHeightPos = aHeight - anAddHeight - 1;
+
+  for (int i = 0; i < anAddWidth && i + aStartWidthPos < aWidth; i++)
+  {
+    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));
+    }
+  }
+  return QPixmap::fromImage(anIcon);
+}
+
+QPixmap lighter(const QString& theIcon, const int theLighterValue)
+{
+  QImage anIcon(theIcon);
+  if (anIcon.isNull())
+    return QPixmap();
+
+  QImage aResult(theIcon);
+  for ( int i = 0; i < anIcon.width(); i++ )
+  {
+    for ( int j = 0; j < anIcon.height(); j++ )
+    {
+      QRgb anRgb = anIcon.pixel( i, j );
+      QColor aPixelColor(qRed(anRgb), qGreen(anRgb), qBlue(anRgb),
+                         qAlpha( aResult.pixel( i, j ) ));
+
+      QColor aLighterColor = aPixelColor.lighter(theLighterValue);
+      aResult.setPixel(i, j, qRgba( aLighterColor.red(), aLighterColor.green(),
+                                    aLighterColor.blue(), aLighterColor.alpha() ) );
     }
   }
-  return aFeature;
+  return QPixmap::fromImage(aResult);
 }
 
-}
\ No newline at end of file
+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;
+}
+
+}
+
+