]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
SketchEntity object for the Sketch features
authornds <natalia.donis@opencascade.com>
Fri, 6 Mar 2015 14:40:41 +0000 (17:40 +0300)
committernds <natalia.donis@opencascade.com>
Fri, 6 Mar 2015 14:40:41 +0000 (17:40 +0300)
32 files changed:
src/Config/Config_PropManager.cpp
src/Config/Config_PropManager.h
src/Model/Model_ResultBody.cpp
src/Model/Model_ResultBody.h
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI_AttributeColor.cpp [new file with mode: 0644]
src/ModelAPI/ModelAPI_AttributeColor.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Feature.h
src/ModelAPI/ModelAPI_Object.h
src/ModelAPI/ModelAPI_Result.h
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_icons.qrc
src/PartSet/icons/color.png [new file with mode: 0644]
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_Arc.h
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Circle.h
src/SketchPlugin/SketchPlugin_Feature.h
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Line.h
src/SketchPlugin/SketchPlugin_Point.cpp
src/SketchPlugin/SketchPlugin_Point.h
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_SketchEntity.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_SketchEntity.h [new file with mode: 0644]
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 82ec43f5871c82fba052e124ee830189943d53ef..ad5ceca9b779bb2a0b0c3865c6625219646e1b86 100644 (file)
@@ -9,6 +9,7 @@
 std::vector<int> stringToRGB(const std::string& theColor);
 int stringToInteger(const std::string& theInt);
 double stringToDouble(const std::string& theDouble);
+bool stringToBoolean(const std::string& theInt);
 
 Config_Properties Config_PropManager::myProps;
 
@@ -121,6 +122,14 @@ double Config_PropManager::real(const std::string& theSection, const std::string
   return stringToDouble(aStr);
 }
 
+bool Config_PropManager::boolean(const std::string& theSection,
+                                 const std::string& theName,
+                                 const std::string& theDefault)
+{
+  std::string aStr = string(theSection, theName, theDefault);
+  return stringToBoolean(aStr);
+}
+
 std::vector<int> stringToRGB(const std::string& theColor)
 {
   std::vector<int> aRes(3);
@@ -173,3 +182,8 @@ double stringToDouble(const std::string& theDouble)
   char* p;
   return strtod(theDouble.c_str(), &p);
 }
+
+bool stringToBoolean(const std::string& theBoolean)
+{
+  return theBoolean == "true";
+}
index c6bba0810a4311ff0bad110bbe7df34a72b18231..9b2ced3eafdf41b28ec17b152c9c459eb04d39f8 100644 (file)
@@ -60,6 +60,10 @@ class Config_PropManager
   CONFIG_EXPORT static double real(const std::string& theSection,
                                    const std::string& theName,
                                    const std::string& theDefault);
+  //! Returns boolean by given section and name
+  CONFIG_EXPORT static bool boolean(const std::string& theSection,
+                                   const std::string& theName,
+                                   const std::string& theDefault);
 
  private:
   CONFIG_EXPORT static Config_Properties myProps; ///< List of all stored properties
index 44b4bdbec6fc1be206bf079efa2be6214be1560a..e2459e7043b67020524056195fdbb2c3ec5b1f64 100644 (file)
@@ -7,6 +7,7 @@
 #include <Model_ResultBody.h>
 #include <Model_Data.h>
 #include <Model_Document.h>
+#include <ModelAPI_AttributeColor.h>
 #include <TNaming_Builder.hxx>
 #include <TNaming_NamedShape.hxx>
 #include <TDataStd_Name.hxx>
 #include <BRep_Tool.hxx>
 #include <GeomAPI_Shape.h>
 #include <GeomAlgoAPI_MakeShape.h>
+#include <Config_PropManager.h>
 // DEB
 //#include <TCollection_AsciiString.hxx>
 //#include <TDF_Tool.hxx>
 //#define DEB_IMPORT 1
 
+#define RESULT_BODY_COLOR "#ff0000"
+
 Model_ResultBody::Model_ResultBody()
 {
   setIsConcealed(false);
 }
 
+void Model_ResultBody::initAttributes()
+{
+  // append the color attribute
+  DataPtr aData = data();
+  aData->addAttribute(COLOR_ID(), ModelAPI_AttributeColor::type());
+  // set the default value
+  bool anIsRandomColor = Config_PropManager::boolean("Visualization", "random_result_color",
+                                                     false);
+  AttributeColorPtr aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>
+                                                    (aData->attribute(COLOR_ID()));
+  if (anIsRandomColor)
+    aColorAttr->setValuesRandom();
+  else {
+    std::vector<int> aRGB;
+    aRGB = Config_PropManager::color("Visualization", "result_body_color", RESULT_BODY_COLOR);
+    aColorAttr->setValues(aRGB[0], aRGB[1], aRGB[2]);
+  }
+}
+
 void Model_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
 {
   std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
index f4fbb7b1f36feaccf10aa9ad5ef8dae5d996efa4..5b849c620b50b64b8fa1b3bad68c0eb68052d0a6 100644 (file)
@@ -29,6 +29,9 @@ class Model_ResultBody : public ModelAPI_ResultBody
   /// label; index in vector corresponds to the label tag
   std::vector<TNaming_Builder*> myBuilders;
 public:
+  /// Request for initialization of data model of the result: adding all attributes
+  virtual void initAttributes();
+
   /// Stores the shape (called by the execution method).
   MODEL_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape);
 
index e8ef2bad290e75210907cb1e53a7561f1cdaad95..497fe5365b604573f73a95f6bc306ea7b45b2ac8 100644 (file)
@@ -9,6 +9,7 @@ SET(PROJECT_HEADERS
     ModelAPI.h
     ModelAPI_Attribute.h
     ModelAPI_AttributeBoolean.h
+    ModelAPI_AttributeColor.h
     ModelAPI_AttributeDocRef.h
     ModelAPI_AttributeDouble.h
     ModelAPI_AttributeInteger.h
@@ -44,6 +45,7 @@ SET(PROJECT_HEADERS
 SET(PROJECT_SOURCES
     ModelAPI_Attribute.cpp
     ModelAPI_AttributeBoolean.cpp
+    ModelAPI_AttributeColor.cpp
     ModelAPI_AttributeDocRef.cpp
     ModelAPI_AttributeDouble.cpp
     ModelAPI_AttributeInteger.cpp
diff --git a/src/ModelAPI/ModelAPI_AttributeColor.cpp b/src/ModelAPI/ModelAPI_AttributeColor.cpp
new file mode 100644 (file)
index 0000000..1909fc3
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModelAPI_AttributeColor.cpp
+// Created:     6 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#include <ModelAPI_AttributeColor.h>
+
+
+std::string ModelAPI_AttributeColor::attributeType()
+{
+  return type();
+}
+
+/// To virtually destroy the fields of successors
+ModelAPI_AttributeColor::~ModelAPI_AttributeColor()
+{
+}
+
+ModelAPI_AttributeColor::ModelAPI_AttributeColor()
+{
+}
diff --git a/src/ModelAPI/ModelAPI_AttributeColor.h b/src/ModelAPI/ModelAPI_AttributeColor.h
new file mode 100644 (file)
index 0000000..945d9f8
--- /dev/null
@@ -0,0 +1,56 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModelAPI_AttributeColor.h
+// Created:     6 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef ModelAPI_AttributeColor_H_
+#define ModelAPI_AttributeColor_H_
+
+#include <ModelAPI.h>
+#include <ModelAPI_Attribute.h>
+
+#include <string>
+
+
+/**\class ModelAPI_AttributeColor
+ * \ingroup DataModel
+ * \brief API for the attribute that contains color (int, int, int).
+ * There is an opportunity to fill the attribute by a random color
+ */
+
+class ModelAPI_AttributeColor : public ModelAPI_Attribute
+{
+ public:
+  /// Defines the color value
+  MODELAPI_EXPORT virtual void setValues(const int theRed,
+                                         const int theGreen,
+                                         const int theBlue) = 0;
+
+  /// Fills the attribute values by a random color
+  MODELAPI_EXPORT virtual void setValuesRandom() = 0;
+
+  /// Returns the color value
+  MODELAPI_EXPORT virtual void values(int& theRed, int& theGreen, int& theBlue) = 0;
+
+  /// Returns the type of this class of attributes
+  MODELAPI_EXPORT static std::string type()
+  {
+    return "Color";
+  }
+
+  /// Returns the type of this class of attributes, not static method
+  MODELAPI_EXPORT virtual std::string attributeType();
+
+  /// To virtually destroy the fields of successors
+  MODELAPI_EXPORT virtual ~ModelAPI_AttributeColor();
+
+ protected:
+  /// Objects are created for features automatically
+  MODELAPI_EXPORT ModelAPI_AttributeColor();
+};
+
+//! Pointer on double attribute
+typedef std::shared_ptr<ModelAPI_AttributeColor> AttributeColorPtr;
+
+#endif
index c7a57a01b3e62738ba9fd576a6d8975ba35c4f3d..e5701200fedbc8755f1c58c1f104aca8ffe4d825 100644 (file)
@@ -49,9 +49,6 @@ class ModelAPI_Feature : public ModelAPI_Object
     return group();
   }
 
-  /// Request for initialization of data model of the feature: adding all attributes
-  virtual void initAttributes() = 0;
-
   /// Computes or recomputes the results
   virtual void execute() = 0;
 
index 45932c039e2046212dd9fa32b6e360d438127a02..485cf2ee1bc3775906dea0052f0376dc240270e2 100644 (file)
@@ -44,6 +44,9 @@ class ModelAPI_Object
   /// Returns the group identifier of this object
   virtual std::string groupName() = 0;
 
+  /// Request for initialization of data model of the object: adding all attributes
+  virtual void initAttributes() = 0;
+
   /// Called on change of any argument-attribute of this object
   /// \param theID identifier of changed attribute
   // MODELAPI_EXPORT
index 28ea36645dd080cc73b63acc41651706e59daa06..776a2839153c4d64efb681044983402b4f8ba551 100644 (file)
@@ -22,7 +22,15 @@ class ModelAPI_Result : public ModelAPI_Object
 {
   bool myIsConcealed; ///< the result is concealed from the data tree (referenced by other objects)
  public:
-   /// Returns true if the result is concealed from the data tree (referenced by other objects)
+
+  /// Reference to the color of the result
+  inline static const std::string& COLOR_ID()
+  {
+    static const std::string MY_COLOR_ID("Color");
+    return MY_COLOR_ID;
+  }
+
+  /// Returns true if the result is concealed from the data tree (referenced by other objects)
   inline bool isConcealed()
   {
     return myIsConcealed;
@@ -34,6 +42,9 @@ class ModelAPI_Result : public ModelAPI_Object
     myIsConcealed = theValue;
   }
 
+  /// Request for initialization of data model of the result: adding all attributes
+  virtual void initAttributes() {};
+
   /// To virtually destroy the fields of successors
   MODELAPI_EXPORT virtual ~ModelAPI_Result();
 
index 3b9e813c2ba6efa80b0280ed04dc5973c70c4943..8ecc6bde02b07a9e6968e518ac3558a97e61778f 100644 (file)
@@ -116,7 +116,8 @@ void fillFeature2Attribute(const QList<ModuleBase_ViewerPrs>& theList,
 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
   : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
     myIsPropertyPanelValueChanged(false), myIsMouseOverWindow(false),
-    myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true)
+    myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
+    myIsPopupMenuActive(false)
 {
   ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
   ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
@@ -236,6 +237,8 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
 {
   get2dPoint(theWnd, theEvent, myClickedPoint);
 
+  myIsPopupMenuActive = theEvent->buttons() & Qt::RightButton;
+
   if (!(theEvent->buttons() & Qt::LeftButton))
     return;
 
@@ -315,6 +318,9 @@ void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseE
 
 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
+  if (myIsPopupMenuActive)
+    myIsPopupMenuActive = false;
+
   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
   ModuleBase_IViewer* aViewer = aWorkshop->viewer();
   if (!aViewer->canDragByMouse())
@@ -727,6 +733,8 @@ bool PartSet_SketcherMgr::canDisplayObject() const
       return aCanDisplay;
     }
   }
+  if (myIsPopupMenuActive)
+    return aCanDisplay;
 
   // during a nested create operation, the feature is redisplayed only if the mouse over view
   // of there was a value modified in the property panel after the mouse left the view
@@ -768,7 +776,7 @@ bool PartSet_SketcherMgr::canChangeConstruction(bool& isConstruction) const
         std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
                             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
         if (aSketchFeature.get() != NULL) {
-          std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
+          std::string anAttribute = SketchPlugin_SketchEntity::CONSTRUCTION_ID();
 
           std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr = 
             std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
@@ -821,7 +829,7 @@ void PartSet_SketcherMgr::setConstruction(const bool isChecked)
         std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
                             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
         if (aSketchFeature.get() != NULL) {
-          std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
+          std::string anAttribute = SketchPlugin_SketchEntity::CONSTRUCTION_ID();
 
           std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr = 
             std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
index 57f17840fda7e640a7901c350c246531a5483b48..6f7cbc8f510b4b352b6d0dd9f65fa4259706f734 100644 (file)
@@ -251,6 +251,7 @@ private:
   bool myIsPropertyPanelValueChanged; /// the state that value in the property panel is changed
   bool myIsMouseOverWindow; /// the state that the mouse over the view
   bool myIsMouseOverViewProcessed; /// the state whether the over view state is processed by mouseMove method
+  bool myIsPopupMenuActive; /// the state of the popup menu is shown
   Point myCurrentPoint;
   Point myClickedPoint;
 
index d77f86d1e03562d02f6a10cafd07c764099f4355..56f1ac3fc83708bdb32db18c07286b58c225aa4b 100644 (file)
@@ -462,7 +462,7 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap
       DataPtr aData = aMyFeature->data();
       AttributeSelectionPtr anAttr = 
         std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-        (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
+        (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
 
       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
       if (anAttr && aRes) {
@@ -495,7 +495,7 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap
       DataPtr aData = aMyFeature->data();
       AttributeSelectionPtr anAttr = 
         std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-        (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
+        (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
 
       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
       if (anAttr && aRes) {
index 5925437ed68ebcdf91fe921535220636c0141e50..1a20133b41d30f23f6d306a6def256f63a7057ca 100644 (file)
@@ -7,6 +7,8 @@
 #include "PartSet_WidgetSketchLabel.h"
 #include "PartSet_Tools.h"
 
+#include "SketchPlugin_SketchEntity.h"
+
 #include <XGUI_Workshop.h>
 #include <XGUI_Displayer.h>
 #include <XGUI_SelectionMgr.h>
@@ -91,7 +93,7 @@ void PartSet_WidgetSketchLabel::onPlaneSelected()
           DataPtr aData = feature()->data();
           AttributeSelectionPtr aSelAttr = 
             std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-            (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
+            (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
           if (aSelAttr) {
             ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs.object());
             if (aRes) {
index 796ec88ef9ccfdc1f81f2ec25c7355ab86cc9f95..d580c0de6a89753e55cecf9f5d1dd217bab46a1b 100644 (file)
@@ -2,6 +2,7 @@
  <qresource>
      <file>icons/arc.png</file>
      <file>icons/circle.png</file>
+     <file>icons/color.png</file>
      <file>icons/point.png</file>
      <file>icons/plane.png</file>
      <file>icons/axis.png</file>
diff --git a/src/PartSet/icons/color.png b/src/PartSet/icons/color.png
new file mode 100644 (file)
index 0000000..41b0b8c
Binary files /dev/null and b/src/PartSet/icons/color.png differ
index 3b9c8dc2647db13f5a63a381a4564c8fca62e806..d4efeee6c8c472a835e077d5d809ca171bf5c333 100644 (file)
@@ -8,6 +8,7 @@ SET(PROJECT_HEADERS
     SketchPlugin_Feature.h
     SketchPlugin_Plugin.h
     SketchPlugin_Sketch.h
+    SketchPlugin_SketchEntity.h
     SketchPlugin_Line.h
     SketchPlugin_Point.h
     SketchPlugin_Circle.h
@@ -30,6 +31,7 @@ SET(PROJECT_SOURCES
     SketchPlugin_Feature.cpp
     SketchPlugin_Plugin.cpp
     SketchPlugin_Sketch.cpp
+    SketchPlugin_SketchEntity.cpp
     SketchPlugin_Line.cpp
     SketchPlugin_Point.cpp
     SketchPlugin_Circle.cpp
index deb2b2faeb4df9d9c5a40f08aa6fd5039b362e9d..f4bc7f93e3e5aca6c75a8b88e3d620cbcc6ab5fd 100644 (file)
@@ -23,7 +23,7 @@
 const double tolerance = 1e-7;
 
 SketchPlugin_Arc::SketchPlugin_Arc()
-    : SketchPlugin_Feature()
+    : SketchPlugin_SketchEntity()
 {
   myStartUpdate = false;
   myEndUpdate = false;
@@ -31,6 +31,8 @@ SketchPlugin_Arc::SketchPlugin_Arc()
 
 void SketchPlugin_Arc::initAttributes()
 {
+  SketchPlugin_SketchEntity::initAttributes();
+
   data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::type());
   data()->addAttribute(START_ID(), GeomDataAPI_Point2D::type());
   data()->addAttribute(END_ID(), GeomDataAPI_Point2D::type());
index 044d074627efede8d9e5d561e4912573078d0603..47a9f9dd45d2d089d1f2c469478ba1631d2b1b17 100644 (file)
@@ -8,7 +8,7 @@
 #define SketchPlugin_Arc_H_
 
 #include "SketchPlugin.h"
-#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_SketchEntity.h>
 #include <SketchPlugin_Sketch.h>
 #include <GeomAPI_IPresentable.h>
 
@@ -19,7 +19,7 @@
  * calculated when there is non-initialized attributes of the arc. The second is a result and
  * it is calculated if all attributes are initialized.
  */
-class SketchPlugin_Arc : public SketchPlugin_Feature, public GeomAPI_IPresentable
+class SketchPlugin_Arc : public SketchPlugin_SketchEntity, public GeomAPI_IPresentable
 {
   /// to avoid cyclic dependencies in automatic updates: they mean that 
   /// update is performed right now and automatic updates are not needed
index e880df9afc2f7e47e06ddb185ae6ea4ce449c4ca..50b387414b82402e10bec366908b2d2d856f24fa 100644 (file)
 #include <GeomAlgoAPI_CompoundBuilder.h>
 
 SketchPlugin_Circle::SketchPlugin_Circle()
-    : SketchPlugin_Feature()
+    : SketchPlugin_SketchEntity()
 {
 }
 
 void SketchPlugin_Circle::initAttributes()
 {
+  SketchPlugin_SketchEntity::initAttributes();
+
   data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::type());
   data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::type());
   data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
index f3434d4b52566d187f150e99915de9cc9a06f509..e4f705e76300fe56dee16c4ab913127247f1b77a 100644 (file)
@@ -8,7 +8,7 @@
 #define SketchPlugin_Circle_H_
 
 #include "SketchPlugin.h"
-#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_SketchEntity.h>
 #include <SketchPlugin_Sketch.h>
 #include <GeomAPI_IPresentable.h>
 
@@ -16,7 +16,7 @@
  * \ingroup Plugins
  * \brief Feature for creation of the new circle in PartSet.
  */
-class SketchPlugin_Circle : public SketchPlugin_Feature 
+class SketchPlugin_Circle : public SketchPlugin_SketchEntity 
 {
  public:
   /// Circle feature kind
index 4be01f0a671d9f67e746adb41159ae4526716c93..b8437dcbcaf7c3674d2399bc47ac87a5d4171668 100644 (file)
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeBoolean.h>
-#include <GeomAPI_ICustomPrs.h>
 
 #include <Config_PropManager.h>
 
-#define SKETCH_EDGE_COLOR "#ff0000"
-#define SKETCH_POINT_COLOR "#ff0000"
-#define SKETCH_EXTERNAL_EDGE_COLOR "#00ff00"
-#define SKETCH_CONSTRUCTION_COLOR "#000000"
-
 class SketchPlugin_Sketch;
 class GeomAPI_Pnt2d;
 class Handle_AIS_InteractiveObject;
@@ -32,25 +26,17 @@ class Handle_AIS_InteractiveObject;
  * \brief Feature for creation of the new feature in PartSet. This is an abstract class to give
  * an interface to create the sketch feature preview.
  */
-class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
+class SketchPlugin_Feature : public ModelAPI_Feature
 {
  public:
-  /// Reference to the construction type of the feature
-  inline static const std::string& CONSTRUCTION_ID()
-  {
-    static const std::string MY_CONSTRUCTION_ID("Construction");
-    return MY_CONSTRUCTION_ID;
-  }
-
-  /// Reference to the external edge or vertex as a AttributeSelection
-  inline static const std::string& EXTERNAL_ID()
+  /// Returns true if this feature must be displayed in the history (top level of Part tree)
+  SKETCHPLUGIN_EXPORT virtual bool isInHistory()
   {
-    static const std::string MY_EXTERNAL_ID("External");
-    return MY_EXTERNAL_ID;
+    return false;
   }
 
-  /// Returns true if this feature must be displayed in the history (top level of Part tree)
-  SKETCHPLUGIN_EXPORT virtual bool isInHistory()
+  /// Returns true of the feature is created basing on the external shape of not-this-sketch object
+  SKETCHPLUGIN_EXPORT virtual bool isExternal() const
   {
     return false;
   }
@@ -70,60 +56,6 @@ class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
   /// Returns true is sketch element is under the rigid constraint
   SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;}
 
-  /// Returns true of the feature is created basing on the external shape of not-this-sketch object
-  inline bool isExternal() const
-  {
-    AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
-    if (aAttr)
-      return aAttr->context().get() != NULL;
-    return false;
-  }
-
-  /// Customize presentation of the feature
-  virtual void customisePresentation(AISObjectPtr thePrs)
-  {
-    std::vector<int> aRGB;
-  
-    int aShapeType = thePrs->getShapeType();
-    if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
-      return;
-
-    std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
-                                   data()->boolean(SketchPlugin_Feature::CONSTRUCTION_ID());
-    bool isConstruction = aConstructionAttr.get() != NULL && aConstructionAttr->value();
-    if (aShapeType == 6) { // if this is an edge
-      if (isConstruction) {
-        thePrs->setWidth(1);
-        thePrs->setLineStyle(3);
-        aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
-                                         SKETCH_CONSTRUCTION_COLOR);
-      }
-      else {
-        thePrs->setWidth(3);
-        thePrs->setLineStyle(0);
-        if (isExternal()) {
-          // Set color from preferences
-          aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
-                                           SKETCH_EXTERNAL_EDGE_COLOR);
-        }
-        else {
-          // Set color from preferences
-          aRGB = Config_PropManager::color("Visualization", "sketch_edge_color",
-                                           SKETCH_EDGE_COLOR);
-        }
-      }
-    }
-    else if (aShapeType == 7) { // otherwise this is a vertex
-      //  thePrs->setPointMarker(6, 2.);
-      // Set color from preferences
-      aRGB = Config_PropManager::color("Visualization", "sketch_point_color",
-                                       SKETCH_POINT_COLOR);
-    }
-
-    if (!aRGB.empty())
-      thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
-  }
-
   /// Returns the sketch of this feature
   SketchPlugin_Sketch* sketch();
 protected:
index ee7193e72b5d7b24ecda26152b6fe58134500c4f..f0c76538a92ff0973a46813f32945c8299bf854c 100644 (file)
 using namespace std;
 
 SketchPlugin_Line::SketchPlugin_Line()
-    : SketchPlugin_Feature()
+    : SketchPlugin_SketchEntity()
 {}
 
 void SketchPlugin_Line::initAttributes()
 {
+  SketchPlugin_SketchEntity::initAttributes();
+
   data()->addAttribute(START_ID(), GeomDataAPI_Point2D::type());
   data()->addAttribute(END_ID(), GeomDataAPI_Point2D::type());
-  data()->addAttribute(CONSTRUCTION_ID(), ModelAPI_AttributeBoolean::type());
   data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
 }
index 1984f8368997b73e299588a6a4a008804c419a48..05d94cc65e59bd582bd6290920a1d7820d995e4a 100644 (file)
@@ -8,7 +8,7 @@
 #define SketchPlugin_Line_H_
 
 #include "SketchPlugin.h"
-#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_SketchEntity.h>
 #include <SketchPlugin_Sketch.h>
 #include <list>
 
@@ -16,7 +16,7 @@
  * \ingroup Plugins
  * \brief Feature for creation of the new part in PartSet.
  */
-class SketchPlugin_Line : public SketchPlugin_Feature
+class SketchPlugin_Line : public SketchPlugin_SketchEntity
 {
  public:
   /// Arc feature kind
index 3fd71b5609e3429a5102ac7b9e314d69982802d2..798140611b2755a7b86248a055617fa84aed4e44 100644 (file)
 using namespace std;
 
 SketchPlugin_Point::SketchPlugin_Point()
+    : SketchPlugin_SketchEntity()
 {
 }
 
 void SketchPlugin_Point::initAttributes()
 {
+  SketchPlugin_SketchEntity::initAttributes();
+
   data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::type());
   data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
index 27a288763194468b636a996a8b723212b0c977a3..4c774715757edc8463ee320102c7699d01f70ed7 100644 (file)
@@ -9,14 +9,14 @@
 
 #include "SketchPlugin.h"
 #include <SketchPlugin_Sketch.h>
-#include "SketchPlugin_Feature.h"
+#include "SketchPlugin_SketchEntity.h"
 #include <list>
 
 /**\class SketchPlugin_Point
  * \ingroup Plugins
  * \brief Feature for creation of a new point.
  */
-class SketchPlugin_Point : public SketchPlugin_Feature
+class SketchPlugin_Point : public SketchPlugin_SketchEntity
 {
  public:
   /// Point feature kind
index f243c86c77aa0da8ca83cdd4beb837b5b2afb54f..c19e27114b2bb001425f78ae9f8b383f6031c5aa 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <SketchPlugin_Sketch.h>
 #include <SketchPlugin_Feature.h>
+#include <SketchPlugin_SketchEntity.h>
 
 #include <memory>
 
@@ -49,9 +50,9 @@ void SketchPlugin_Sketch::initAttributes()
   data()->addAttribute(SketchPlugin_Sketch::NORM_ID(), GeomDataAPI_Dir::type());
   data()->addAttribute(SketchPlugin_Sketch::FEATURES_ID(), ModelAPI_AttributeRefList::type());
   // the selected face, base for the sketcher plane, not obligatory
-  data()->addAttribute(SketchPlugin_Feature::EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+  data()->addAttribute(SketchPlugin_SketchEntity::EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
   ModelAPI_Session::get()->validators()->registerNotObligatory(
-    getKind(), SketchPlugin_Feature::EXTERNAL_ID());
+    getKind(), SketchPlugin_SketchEntity::EXTERNAL_ID());
 }
 
 void SketchPlugin_Sketch::execute()
@@ -83,13 +84,13 @@ void SketchPlugin_Sketch::execute()
       if (!aFeature->sketch()) // on load document the back references are missed
         aFeature->setSketch(this);
       // do not include the external edges into the result
-      if (aFeature->data()->attribute(SketchPlugin_Feature::EXTERNAL_ID())) {
-        if (aFeature->data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value())
+      if (aFeature->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())) {
+        if (aFeature->data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->value())
           continue;
       }
       // do not include the construction entities in the result
-      if (aFeature->data()->attribute(SketchPlugin_Feature::CONSTRUCTION_ID())) {
-        if (aFeature->data()->boolean(SketchPlugin_Feature::CONSTRUCTION_ID())->value())
+      if (aFeature->data()->attribute(SketchPlugin_SketchEntity::CONSTRUCTION_ID())) {
+        if (aFeature->data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID())->value())
           continue;
       }
 
@@ -262,9 +263,9 @@ void SketchPlugin_Sketch::erase()
 }
 
 void SketchPlugin_Sketch::attributeChanged(const std::string& theID) {
-  if (theID == SketchPlugin_Feature::EXTERNAL_ID()) {
+  if (theID == SketchPlugin_SketchEntity::EXTERNAL_ID()) {
     std::shared_ptr<GeomAPI_Shape> aSelection = 
-      data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value();
+      data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->value();
     if (aSelection) { // update arguments due to the selection value
       // update the sketch plane
       std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aSelection);
diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.cpp b/src/SketchPlugin/SketchPlugin_SketchEntity.cpp
new file mode 100644 (file)
index 0000000..1e7c4de
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+#include "SketchPlugin_SketchEntity.h"
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+SketchPlugin_SketchEntity::SketchPlugin_SketchEntity()
+: SketchPlugin_Feature()
+{
+}
+
+void SketchPlugin_SketchEntity::initAttributes()
+{
+  data()->addAttribute(CONSTRUCTION_ID(), ModelAPI_AttributeBoolean::type());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CONSTRUCTION_ID());
+}
diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.h b/src/SketchPlugin/SketchPlugin_SketchEntity.h
new file mode 100644 (file)
index 0000000..c0c0925
--- /dev/null
@@ -0,0 +1,112 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SketchPlugin_SketchEntity.h
+// Created:     05 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef SketchPlugin_SketchEntity_H_
+#define SketchPlugin_SketchEntity_H_
+
+#include "SketchPlugin.h"
+#include "SketchPlugin_Feature.h"
+
+#include <ModelAPI_CompositeFeature.h>
+#include <GeomAPI_Shape.h>
+#include <GeomAPI_AISObject.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <GeomAPI_ICustomPrs.h>
+
+#include <Config_PropManager.h>
+
+#define SKETCH_EDGE_COLOR "#ff0000"
+#define SKETCH_POINT_COLOR "#ff0000"
+#define SKETCH_EXTERNAL_EDGE_COLOR "#00ff00"
+#define SKETCH_CONSTRUCTION_COLOR "#000000"
+
+/**\class SketchPlugin_SketchEntity
+ * \ingroup Plugins
+ * \brief Sketch Entity for creation of the new feature in PartSet. This is an abstract class to give
+ * an interface to create the entity features such as line, circle, arc and point.
+ */
+class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_ICustomPrs
+{
+ public:
+  /// Reference to the construction type of the feature
+  inline static const std::string& CONSTRUCTION_ID()
+  {
+    static const std::string MY_CONSTRUCTION_ID("Construction");
+    return MY_CONSTRUCTION_ID;
+  }
+
+  /// Reference to the external edge or vertex as a AttributeSelection
+  inline static const std::string& EXTERNAL_ID()
+  {
+    static const std::string MY_EXTERNAL_ID("External");
+    return MY_EXTERNAL_ID;
+  }
+
+  /// Request for initialization of data model of the feature: adding all attributes
+  virtual void initAttributes();
+
+  /// Returns true of the feature is created basing on the external shape of not-this-sketch object
+  virtual bool isExternal() const
+  {
+    AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
+    if (aAttr)
+      return aAttr->context().get() != NULL;
+    return false;
+  }
+
+  /// Customize presentation of the feature
+  virtual void customisePresentation(AISObjectPtr thePrs)
+  {
+    std::vector<int> aRGB;
+  
+    int aShapeType = thePrs->getShapeType();
+    if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
+      return;
+
+    std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
+                                   data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID());
+    bool isConstruction = aConstructionAttr.get() != NULL && aConstructionAttr->value();
+    if (aShapeType == 6) { // if this is an edge
+      if (isConstruction) {
+        thePrs->setWidth(1);
+        thePrs->setLineStyle(3);
+        aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
+                                         SKETCH_CONSTRUCTION_COLOR);
+      }
+      else {
+        thePrs->setWidth(3);
+        thePrs->setLineStyle(0);
+        if (isExternal()) {
+          // Set color from preferences
+          aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
+                                           SKETCH_EXTERNAL_EDGE_COLOR);
+        }
+        else {
+          // Set color from preferences
+          aRGB = Config_PropManager::color("Visualization", "sketch_edge_color",
+                                           SKETCH_EDGE_COLOR);
+        }
+      }
+    }
+    else if (aShapeType == 7) { // otherwise this is a vertex
+      //  thePrs->setPointMarker(6, 2.);
+      // Set color from preferences
+      aRGB = Config_PropManager::color("Visualization", "sketch_point_color",
+                                       SKETCH_POINT_COLOR);
+    }
+
+    if (!aRGB.empty())
+      thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
+  }
+
+protected:
+  /// initializes mySketch
+  SketchPlugin_SketchEntity();
+};
+
+#endif
index 2f2ff1206a37483e2afef3f205299847835b4ea3..ece5d2d2bafb64b118d6c1ea1e006ff4ef1452c2 100644 (file)
@@ -53,10 +53,14 @@ void XGUI_ContextMenuMgr::createActions()
   if (!aDesktop)
     aDesktop = myWorkshop->salomeConnector()->desktop();
   aDesktop->addAction(aAction);
+
   addAction("DELETE_CMD", aAction);
   aAction->setShortcut(Qt::Key_Delete);
   aAction->setShortcutContext(Qt::ApplicationShortcut);
 
+  aAction = new QAction(QIcon(":pictures/color.png"), tr("Color"), this);
+  addAction("COLOR_CMD", aAction);
+
   aAction = new QAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), this);
   addAction("SHOW_CMD", aAction);
 
@@ -188,6 +192,9 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
     if (hasFeature)
       aMenu->addAction(action("DELETE_CMD"));
   }
+  if (myWorkshop->canChangeColor())
+    aMenu->addAction(action("COLOR_CMD"));
+
   aMenu->addSeparator();
   aMenu->addActions(myWorkshop->objectBrowser()->actions());
 
@@ -257,6 +264,8 @@ void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const
       aSubMenu->addActions(aMDI->actions());
     }
   }
+  if (myWorkshop->canChangeColor())
+    theMenu->addAction(action("COLOR_CMD"));
 
   ModuleBase_IModule* aModule = myWorkshop->module();
   if (aModule)
index 02fe22ef83ce679d0bbc46b6ea8ef752abde5d61..633b08dc2902516c45f1f4bc5a683b88b26a0864 100644 (file)
@@ -36,6 +36,7 @@
 #include <ModelAPI_AttributeDocRef.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_ResultGroup.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultBody.h>
 
@@ -1239,6 +1240,8 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
     activatePart(ResultPartPtr());
   else if (theId == "DELETE_CMD")
     deleteObjects(aObjects);
+  else if (theId == "COLOR_CMD")
+    changeColor(aObjects);
   else if (theId == "SHOW_CMD")
     showObjects(aObjects, true);
   else if (theId == "HIDE_CMD")
@@ -1372,6 +1375,72 @@ These features will be deleted also. Would you like to continue?")).arg(aNames),
   updateCommandStatus();
 }
 
+bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
+{
+  bool isFoundResultType = false;
+  foreach(ObjectPtr anObj, theObjects)
+  {
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+    if (aResult.get() == NULL)
+      continue;
+
+    isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
+    if (isFoundResultType)
+      break;
+  }
+  return isFoundResultType;
+}
+
+//**************************************************************
+bool XGUI_Workshop::canChangeColor() const
+{
+  QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+
+  std::set<std::string> aTypes;
+  aTypes.insert(ModelAPI_ResultGroup::group());
+  aTypes.insert(ModelAPI_ResultConstruction::group());
+  aTypes.insert(ModelAPI_ResultBody::group());
+  return hasResults(aObjects, aTypes);
+}
+
+//**************************************************************
+#include <QDialog>
+#include <QHBoxLayout>
+#include <QLineEdit>
+void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
+{
+  // 1. find the initial value of the material
+  std::string aFirstValue = "";
+  foreach(ObjectPtr anObj, theObjects)
+  {
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+    if (aResult.get() == NULL)
+      continue;
+  }
+
+  // 2. show the dialog to change the value
+  QDialog aDlg;
+  QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
+
+  QLineEdit* anEditor = new QLineEdit("QString::number(theValue)", &aDlg);
+  anEditor->setText(aFirstValue.c_str());
+  anEditor->selectAll();
+  aLay->addWidget(anEditor);
+
+  QPoint aPoint = QCursor::pos();
+  aDlg.move(aPoint);
+
+  bool isDone = aDlg.exec() == QDialog::Accepted;
+  if (!isDone)
+    return;
+
+  std::string aValue = anEditor->text().toStdString();
+
+  // 3. abort the previous operation and start a new one
+
+  // 4. set the value to all results
+}
+
 //**************************************************************
 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
 {
index 3f5d8f2c1f10fb7afe73e430aa7bca542bc4b590..c2b067741db3bb8162dd48b7565ab87046036251 100644 (file)
@@ -166,6 +166,15 @@ Q_OBJECT
   //! Delete features
   void deleteObjects(const QObjectPtrList& theList);
 
+  //! Returns true if there is at least one selected body/construction/group result
+  //! \return boolean value
+  bool canChangeColor() const;
+
+  //! Change color of the features if it is possible
+  //! The operation is available for construction, body and group results
+  //! theObjects a list of selected objects
+  void changeColor(const QObjectPtrList& theObjects);
+
   //! Show the given features in 3d Viewer
   void showObjects(const QObjectPtrList& theList, bool isVisible);