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;
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);
char* p;
return strtod(theDouble.c_str(), &p);
}
+
+bool stringToBoolean(const std::string& theBoolean)
+{
+ return theBoolean == "true";
+}
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
#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());
/// 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);
ModelAPI.h
ModelAPI_Attribute.h
ModelAPI_AttributeBoolean.h
+ ModelAPI_AttributeColor.h
ModelAPI_AttributeDocRef.h
ModelAPI_AttributeDouble.h
ModelAPI_AttributeInteger.h
SET(PROJECT_SOURCES
ModelAPI_Attribute.cpp
ModelAPI_AttributeBoolean.cpp
+ ModelAPI_AttributeColor.cpp
ModelAPI_AttributeDocRef.cpp
ModelAPI_AttributeDouble.cpp
ModelAPI_AttributeInteger.cpp
--- /dev/null
+// 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()
+{
+}
--- /dev/null
+// 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
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;
/// 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
{
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;
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();
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();
{
get2dPoint(theWnd, theEvent, myClickedPoint);
+ myIsPopupMenuActive = theEvent->buttons() & Qt::RightButton;
+
if (!(theEvent->buttons() & Qt::LeftButton))
return;
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())
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
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));
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));
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;
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) {
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) {
#include "PartSet_WidgetSketchLabel.h"
#include "PartSet_Tools.h"
+#include "SketchPlugin_SketchEntity.h"
+
#include <XGUI_Workshop.h>
#include <XGUI_Displayer.h>
#include <XGUI_SelectionMgr.h>
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) {
<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>
SketchPlugin_Feature.h
SketchPlugin_Plugin.h
SketchPlugin_Sketch.h
+ SketchPlugin_SketchEntity.h
SketchPlugin_Line.h
SketchPlugin_Point.h
SketchPlugin_Circle.h
SketchPlugin_Feature.cpp
SketchPlugin_Plugin.cpp
SketchPlugin_Sketch.cpp
+ SketchPlugin_SketchEntity.cpp
SketchPlugin_Line.cpp
SketchPlugin_Point.cpp
SketchPlugin_Circle.cpp
const double tolerance = 1e-7;
SketchPlugin_Arc::SketchPlugin_Arc()
- : SketchPlugin_Feature()
+ : SketchPlugin_SketchEntity()
{
myStartUpdate = false;
myEndUpdate = false;
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());
#define SketchPlugin_Arc_H_
#include "SketchPlugin.h"
-#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_SketchEntity.h>
#include <SketchPlugin_Sketch.h>
#include <GeomAPI_IPresentable.h>
* 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
#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());
#define SketchPlugin_Circle_H_
#include "SketchPlugin.h"
-#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_SketchEntity.h>
#include <SketchPlugin_Sketch.h>
#include <GeomAPI_IPresentable.h>
* \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
#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;
* \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;
}
/// 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:
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());
}
#define SketchPlugin_Line_H_
#include "SketchPlugin.h"
-#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_SketchEntity.h>
#include <SketchPlugin_Sketch.h>
#include <list>
* \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
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());
#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
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_SketchEntity.h>
#include <memory>
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()
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;
}
}
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);
--- /dev/null
+// 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());
+}
--- /dev/null
+// 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
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);
if (hasFeature)
aMenu->addAction(action("DELETE_CMD"));
}
+ if (myWorkshop->canChangeColor())
+ aMenu->addAction(action("COLOR_CMD"));
+
aMenu->addSeparator();
aMenu->addActions(myWorkshop->objectBrowser()->actions());
aSubMenu->addActions(aMDI->actions());
}
}
+ if (myWorkshop->canChangeColor())
+ theMenu->addAction(action("COLOR_CMD"));
ModuleBase_IModule* aModule = myWorkshop->module();
if (aModule)
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Validator.h>
+#include <ModelAPI_ResultGroup.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_ResultBody.h>
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")
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)
{
//! 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);