From: nds Date: Fri, 6 Mar 2015 14:40:41 +0000 (+0300) Subject: SketchEntity object for the Sketch features X-Git-Tag: V_1.1.0~145^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=93c7fa6135463fb0a202cf94f30da60316795a04;p=modules%2Fshaper.git SketchEntity object for the Sketch features --- diff --git a/src/Config/Config_PropManager.cpp b/src/Config/Config_PropManager.cpp index 82ec43f58..ad5ceca9b 100644 --- a/src/Config/Config_PropManager.cpp +++ b/src/Config/Config_PropManager.cpp @@ -9,6 +9,7 @@ std::vector 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 stringToRGB(const std::string& theColor) { std::vector 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"; +} diff --git a/src/Config/Config_PropManager.h b/src/Config/Config_PropManager.h index c6bba0810..9b2ced3ea 100644 --- a/src/Config/Config_PropManager.h +++ b/src/Config/Config_PropManager.h @@ -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 diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index 44b4bdbec..e2459e704 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -30,16 +31,38 @@ #include #include #include +#include // DEB //#include //#include //#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 + (aData->attribute(COLOR_ID())); + if (anIsRandomColor) + aColorAttr->setValuesRandom(); + else { + std::vector 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& theShape) { std::shared_ptr aData = std::dynamic_pointer_cast(data()); diff --git a/src/Model/Model_ResultBody.h b/src/Model/Model_ResultBody.h index f4fbb7b1f..5b849c620 100644 --- a/src/Model/Model_ResultBody.h +++ b/src/Model/Model_ResultBody.h @@ -29,6 +29,9 @@ class Model_ResultBody : public ModelAPI_ResultBody /// label; index in vector corresponds to the label tag std::vector 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& theShape); diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index e8ef2bad2..497fe5365 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -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 index 000000000..1909fc325 --- /dev/null +++ b/src/ModelAPI/ModelAPI_AttributeColor.cpp @@ -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 + + +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 index 000000000..945d9f868 --- /dev/null +++ b/src/ModelAPI/ModelAPI_AttributeColor.h @@ -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 +#include + +#include + + +/**\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 AttributeColorPtr; + +#endif diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index c7a57a01b..e5701200f 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -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; diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h index 45932c039..485cf2ee1 100644 --- a/src/ModelAPI/ModelAPI_Object.h +++ b/src/ModelAPI/ModelAPI_Object.h @@ -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 diff --git a/src/ModelAPI/ModelAPI_Result.h b/src/ModelAPI/ModelAPI_Result.h index 28ea36645..776a28391 100644 --- a/src/ModelAPI/ModelAPI_Result.h +++ b/src/ModelAPI/ModelAPI_Result.h @@ -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(); diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 3b9e813c2..8ecc6bde0 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -116,7 +116,8 @@ void fillFeature2Attribute(const QList& 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 aSketchFeature = std::dynamic_pointer_cast(aFeature); if (aSketchFeature.get() != NULL) { - std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID(); + std::string anAttribute = SketchPlugin_SketchEntity::CONSTRUCTION_ID(); std::shared_ptr aConstructionAttr = std::dynamic_pointer_cast(aSketchFeature->data()->attribute(anAttribute)); @@ -821,7 +829,7 @@ void PartSet_SketcherMgr::setConstruction(const bool isChecked) std::shared_ptr aSketchFeature = std::dynamic_pointer_cast(aFeature); if (aSketchFeature.get() != NULL) { - std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID(); + std::string anAttribute = SketchPlugin_SketchEntity::CONSTRUCTION_ID(); std::shared_ptr aConstructionAttr = std::dynamic_pointer_cast(aSketchFeature->data()->attribute(anAttribute)); diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 57f17840f..6f7cbc8f5 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -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; diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index d77f86d1e..56f1ac3fc 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -462,7 +462,7 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap DataPtr aData = aMyFeature->data(); AttributeSelectionPtr anAttr = std::dynamic_pointer_cast - (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID())); + (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); ResultPtr aRes = std::dynamic_pointer_cast(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 - (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID())); + (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); ResultPtr aRes = std::dynamic_pointer_cast(theObject); if (anAttr && aRes) { diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 5925437ed..1a20133b4 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -7,6 +7,8 @@ #include "PartSet_WidgetSketchLabel.h" #include "PartSet_Tools.h" +#include "SketchPlugin_SketchEntity.h" + #include #include #include @@ -91,7 +93,7 @@ void PartSet_WidgetSketchLabel::onPlaneSelected() DataPtr aData = feature()->data(); AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast - (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID())); + (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); if (aSelAttr) { ResultPtr aRes = std::dynamic_pointer_cast(aPrs.object()); if (aRes) { diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index 796ec88ef..d580c0de6 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -2,6 +2,7 @@ icons/arc.png icons/circle.png + icons/color.png icons/point.png icons/plane.png icons/axis.png diff --git a/src/PartSet/icons/color.png b/src/PartSet/icons/color.png new file mode 100644 index 000000000..41b0b8ce0 Binary files /dev/null and b/src/PartSet/icons/color.png differ diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 3b9c8dc26..d4efeee6c 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -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 diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index deb2b2fae..f4bc7f93e 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -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()); diff --git a/src/SketchPlugin/SketchPlugin_Arc.h b/src/SketchPlugin/SketchPlugin_Arc.h index 044d07462..47a9f9dd4 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.h +++ b/src/SketchPlugin/SketchPlugin_Arc.h @@ -8,7 +8,7 @@ #define SketchPlugin_Arc_H_ #include "SketchPlugin.h" -#include +#include #include #include @@ -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 diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index e880df9af..50b387414 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -22,12 +22,14 @@ #include 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()); diff --git a/src/SketchPlugin/SketchPlugin_Circle.h b/src/SketchPlugin/SketchPlugin_Circle.h index f3434d4b5..e4f705e76 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.h +++ b/src/SketchPlugin/SketchPlugin_Circle.h @@ -8,7 +8,7 @@ #define SketchPlugin_Circle_H_ #include "SketchPlugin.h" -#include +#include #include #include @@ -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 diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 4be01f0a6..b8437dcbc 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -14,15 +14,9 @@ #include #include #include -#include #include -#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 aRGB; - - int aShapeType = thePrs->getShapeType(); - if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/) - return; - - std::shared_ptr 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: diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index ee7193e72..f0c76538a 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -23,14 +23,15 @@ 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()); } diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h index 1984f8368..05d94cc65 100644 --- a/src/SketchPlugin/SketchPlugin_Line.h +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -8,7 +8,7 @@ #define SketchPlugin_Line_H_ #include "SketchPlugin.h" -#include +#include #include #include @@ -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 diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index 3fd71b560..798140611 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -21,11 +21,14 @@ 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()); diff --git a/src/SketchPlugin/SketchPlugin_Point.h b/src/SketchPlugin/SketchPlugin_Point.h index 27a288763..4c7747157 100644 --- a/src/SketchPlugin/SketchPlugin_Point.h +++ b/src/SketchPlugin/SketchPlugin_Point.h @@ -9,14 +9,14 @@ #include "SketchPlugin.h" #include -#include "SketchPlugin_Feature.h" +#include "SketchPlugin_SketchEntity.h" #include /**\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 diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index f243c86c7..c19e27114 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -29,6 +29,7 @@ #include #include +#include #include @@ -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 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 aPlane = GeomAlgoAPI_FaceBuilder::plane(aSelection); diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.cpp b/src/SketchPlugin/SketchPlugin_SketchEntity.cpp new file mode 100644 index 000000000..1e7c4de3b --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.cpp @@ -0,0 +1,17 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +#include "SketchPlugin_SketchEntity.h" + +#include +#include + +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 index 000000000..c0c092563 --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.h @@ -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 +#include +#include +#include +#include +#include +#include + +#include + +#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 aRGB; + + int aShapeType = thePrs->getShapeType(); + if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/) + return; + + std::shared_ptr 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 diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 2f2ff1206..ece5d2d2b 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -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) diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 02fe22ef8..633b08dc2 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -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& theTypes) +{ + bool isFoundResultType = false; + foreach(ObjectPtr anObj, theObjects) + { + ResultPtr aResult = std::dynamic_pointer_cast(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 aTypes; + aTypes.insert(ModelAPI_ResultGroup::group()); + aTypes.insert(ModelAPI_ResultConstruction::group()); + aTypes.insert(ModelAPI_ResultBody::group()); + return hasResults(aObjects, aTypes); +} + +//************************************************************** +#include +#include +#include +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(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) { diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 3f5d8f2c1..c2b067741 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -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);