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
// register construction properties
Config_PropManager::registerProp("Visualization", "import_feature_color", "Imported feature color",
Config_Prop::Color, IMPORTED_FEATURE_COLOR);
+
+ // register random result color properties
+ Config_PropManager::registerProp("Visualization", "random_result_color", "Use random color for results",
+ Config_Prop::Bool, "false");
}
FeaturePtr ExchangePlugin_Plugin::createFeature(string theFeatureID)
Model_AttributeRefAttr.h
Model_AttributeRefList.h
Model_AttributeBoolean.h
+ Model_AttributeColor.h
Model_AttributeString.h
Model_AttributeInteger.h
Model_AttributeSelection.h
Model_AttributeRefAttr.cpp
Model_AttributeRefList.cpp
Model_AttributeBoolean.cpp
+ Model_AttributeColor.cpp
Model_AttributeString.cpp
Model_AttributeInteger.cpp
Model_AttributeSelection.cpp
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: Model_AttributeColor.cpp
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#include <Model_AttributeColor.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+
+#include <Standard_TypeDef.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TCollection_ExtendedString.hxx>
+#include <TDataStd_Integer.hxx>
+#include <TDataStd_Name.hxx>
+
+#include <string>
+
+void Model_AttributeColor::setValues(const int theRed,
+ const int theGreen,
+ const int theBlue)
+{
+ if (!myIsInitialized || myRed->Get() != theRed ||
+ myGreen->Get() != theGreen || myBlue->Get() != theBlue) {
+ myRed->Set(theRed);
+ myGreen->Set(theGreen);
+ myBlue->Set(theBlue);
+
+ owner()->data()->sendAttributeUpdated(this);
+ }
+}
+
+void Model_AttributeColor::setValuesRandom()
+{
+ setValues(300, 150, 40);
+}
+
+void Model_AttributeColor::values(int& theRed, int& theGreen, int& theBlue)
+{
+ theRed = myRed->Get();
+ theGreen = myGreen->Get();
+ theBlue = myBlue->Get();
+}
+
+Model_AttributeColor::Model_AttributeColor(TDF_Label& theLabel)
+{
+ // check the attribute could be already presented in this doc (after load document)
+ myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), myRed) == Standard_True;
+ if (!myIsInitialized) {
+ // create attribute: not initialized by value yet, just zero
+ myRed = TDataStd_Integer::Set(theLabel, 0);
+ myGreen = TDataStd_Integer::Set(theLabel, 0);
+ myBlue = TDataStd_Integer::Set(theLabel, 0);
+ }
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: Model_AttributeColor.h
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef MODEL_ATTRIBUTECOLOR_H_
+#define MODEL_ATTRIBUTECOLOR_H_
+
+#include <Model.h>
+#include <ModelAPI_AttributeColor.h>
+
+#include <TDF_Label.hxx>
+#include <TDataStd_Integer.hxx>
+
+#include <string>
+
+/**\class Model_AttributeColor
+ * \ingroup DataModel
+ * \brief Attribute that contains three integer values which define the color.
+ */
+
+class Model_AttributeColor : public ModelAPI_AttributeColor
+{
+ Handle_TDataStd_Integer myRed;
+ Handle_TDataStd_Integer myGreen;
+ Handle_TDataStd_Integer myBlue;
+ public:
+ /// Defines the color value
+ /// \param theRed the red part of the color
+ /// \param theRed the green part of the color
+ /// \param theRed the blue part of the color
+ MODELAPI_EXPORT virtual void setValues(const int theRed,
+ const int theGreen,
+ const int theBlue);
+
+ /// Fills the attribute values by a random color
+ MODELAPI_EXPORT virtual void setValuesRandom();
+
+ /// Returns the color value
+ MODELAPI_EXPORT virtual void values(int& theRed, int& theGreen, int& theBlue);
+
+ protected:
+ /// Initializes attibutes
+ Model_AttributeColor(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
#include <Model_AttributeString.h>
#include <Model_AttributeSelection.h>
#include <Model_AttributeSelectionList.h>
+#include <Model_AttributeColor.h>
#include <Model_Events.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
anAttr = new Model_AttributeRefAttr(anAttrLab);
} else if (theAttrType == ModelAPI_AttributeRefList::type()) {
anAttr = new Model_AttributeRefList(anAttrLab);
+ } else if (theAttrType == ModelAPI_AttributeColor::type()) {
+ anAttr = new Model_AttributeColor(anAttrLab);
}
// create also GeomData attributes here because only here the OCAF strucure is known
else if (theAttrType == GeomData_Point::type()) {
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
if (aFeature) {
setUniqueName(aFeature); // must be before "initAttributes" because duplicate part uses name
- aFeature->initAttributes();
}
+ theObj->initAttributes();
}
void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool theUpdateReferences)
#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). The color is in the range [0, 255]
+ * There is an opportunity to fill the attribute by a random color
+ */
+
+class ModelAPI_AttributeColor : public ModelAPI_Attribute
+{
+ public:
+ /// Defines the color value
+ /// \param theRed the red part of the color
+ /// \param theRed the green part of the color
+ /// \param theRed the blue part of the color
+ 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();
/// \return the boolean result
std::string getDefaultValue() const { return myDefaultValue; }
+ /// Returns true, if the obligatory value of the widget is not defined in the XML or has true value
+ /// \return the boolean result
+ bool isObligatory() const { return myIsObligatory; }
+
/// Defines if it is supposed that the widget should interact with the viewer.
virtual bool isViewerSelector() { return false; }
if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
/// If last line finished on vertex the lines creation sequence has to be break
ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+ ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
- if (aWidgets.last() == aPanel->activeWidget()) {
- myRestartingMode = RM_Forbided;
+ QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
+ bool aFoundWidget = false;
+ bool aFoundObligatory = false;
+ for (; anIt != aLast && !aFoundObligatory; anIt++) {
+ if (!aFoundWidget)
+ aFoundWidget = *anIt == anActiveWidget;
+ else
+ aFoundObligatory = (*anIt)->isObligatory();
}
+ if (!aFoundObligatory)
+ myRestartingMode = RM_Forbided;
}
}
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) {
const std::list<std::string>& theArguments,
const AttributePtr& theAttribute) const
{
- return PartSet_DifferentObjectsValidator::isValid(theAttribute, theArguments);
+ if (PartSet_DifferentObjectsValidator::isValid(theAttribute, theArguments)) {
+ std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
+ theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
+ std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+ for(; anAttr != anAttrs.end(); anAttr++) {
+ if (*anAttr) {
+ std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+ // check the object is already presented
+ if (!aRef->isObject() && aRef->attr() == theAttribute)
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
}
bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute,
#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
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
aFactory->registerValidator("SketchPlugin_DistanceAttr",
new SketchPlugin_DistanceAttrValidator);
- aFactory->registerValidator("SketchPlugin_DifferentObjects",
- new SketchPlugin_DifferentObjectsValidator);
+ //aFactory->registerValidator("SketchPlugin_DifferentObjects",
+ // new SketchPlugin_DifferentObjectsValidator);
aFactory->registerValidator("SketchPlugin_ResultPoint", new SketchPlugin_ResultPointValidator);
aFactory->registerValidator("SketchPlugin_ResultLine", new SketchPlugin_ResultLineValidator);
aFactory->registerValidator("SketchPlugin_ResultArc", new SketchPlugin_ResultArcValidator);
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
return isValid(theAttribute, theArguments);
}
-bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
- const std::list<std::string>& theArguments,
- const ObjectPtr& theObject) const
-{
- std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
- theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
- std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
- for(; anAttr != anAttrs.end(); anAttr++) {
- if (*anAttr) {
- std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
- // check the object is already presented
- if (aRef->isObject() && aRef->object() == theObject)
- return false;
- }
- }
- return true;
-}
+//bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
+// const std::list<std::string>& theArguments,
+// const ObjectPtr& theObject) const
+//{
+// std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
+// theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
+// std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+// for(; anAttr != anAttrs.end(); anAttr++) {
+// if (*anAttr) {
+// std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+// std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+// // check the object is already presented
+// if (aRef->isObject() && aRef->object() == theObject)
+// return false;
+// }
+// }
+// return true;
+//}
-bool SketchPlugin_DifferentObjectsValidator::isValid(
- const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
-{
- std::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
- if (anOrigAttr && anOrigAttr->isObject()) {
- const ObjectPtr& anObj = theAttribute->owner();
- const FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
+//bool SketchPlugin_DifferentObjectsValidator::isValid(
+// const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+//{
+// std::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr =
+// std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+// if (anOrigAttr && anOrigAttr->isObject()) {
+// const ObjectPtr& anObj = theAttribute->owner();
+// const FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
+//
+// std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
+// aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
+// std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+// for(; anAttr != anAttrs.end(); anAttr++) {
+// if (*anAttr && *anAttr != theAttribute) {
+// std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+// std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+// // check the object is already presented
+// if (aRef->isObject() && aRef->object() == anOrigAttr->object())
+// return false;
+// }
+// }
+// }
+// return true;
+//}
- std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
- aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
- std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
- for(; anAttr != anAttrs.end(); anAttr++) {
- if (*anAttr && *anAttr != theAttribute) {
- std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
- // check the object is already presented
- if (aRef->isObject() && aRef->object() == anOrigAttr->object())
- return false;
- }
- }
- }
- return true;
-}
-
-bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
- const std::list<std::string>& theArguments, const AttributePtr& theAttribute) const
-{
- std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
- theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
- std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
- for(; anAttr != anAttrs.end(); anAttr++) {
- if (*anAttr) {
- std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
- // check the object is already presented
- if (!aRef->isObject() && aRef->attr() == theAttribute)
- return false;
- }
- }
- return true;
-}
+//bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
+// const std::list<std::string>& theArguments, const AttributePtr& theAttribute) const
+//{
+// std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
+// theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
+// std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+// for(; anAttr != anAttrs.end(); anAttr++) {
+// if (*anAttr) {
+// std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+// std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
+// // check the object is already presented
+// if (!aRef->isObject() && aRef->attr() == theAttribute)
+// return false;
+// }
+// }
+// return true;
+//}
* Check that there is no same object was already selected in the feature.
* For an example: to avoid perpendicularity on line and the same line.
*/
-class SketchPlugin_DifferentObjectsValidator : public ModelAPI_RefAttrValidator
-{
- public:
- //! returns true if attribute is valid
- //! \param theAttribute the checked attribute
- //! \param theArguments arguments of the attribute
- virtual bool isValid(
- const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const;
- //! Returns true if object is good for the feature attribute
- virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
- const ObjectPtr& theObject) const;
- //! Returns true if the attribute is good for the feature attribute
- virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
- const AttributePtr& theAttribute) const;
-};
+// Use PartSet_DifferentObjectsValidator
+//class SketchPlugin_DifferentObjectsValidator : public ModelAPI_RefAttrValidator
+//{
+// public:
+// //! returns true if attribute is valid
+// //! \param theAttribute the checked attribute
+// //! \param theArguments arguments of the attribute
+// virtual bool isValid(
+// const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const;
+// //! Returns true if object is good for the feature attribute
+// virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
+// const ObjectPtr& theObject) const;
+// //! Returns true if the attribute is good for the feature attribute
+// virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
+// const AttributePtr& theAttribute) const;
+//};
#endif
label="Last object"
tooltip="Select point, line end point, line, center of circle or arc."
shape_types="edge vertex">
- <validator id="SketchPlugin_DifferentObjects"/>
+ <validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
<selection_filter id="MultiFilter" parameters="line,vertex"/>
<sketch_constraint_shape_selector id="ConstraintEntityB" label="Last line" tooltip="Select a line"
shape_types="edge">
<selection_filter id="EdgeFilter" parameters="line"/>
- <validator id="SketchPlugin_DifferentObjects"/>
+ <validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
</sketch_constraint_shape_selector>
<sketch_constraint_shape_selector id="ConstraintEntityB"
label="Last line" tooltip="Select an line"
shape_types="edge">
- <validator id="SketchPlugin_DifferentObjects"/>
+ <validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
<selection_filter id="EdgeFilter" parameters="line"/>
</sketch_constraint_shape_selector>
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_Data.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_AttributeColor.h>
#include <ModuleBase_ResultPrs.h>
aContext->Display(anAISIO, false);
aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
- // Customization of presentation
- FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
- if (aFeature.get() != NULL) {
- GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
- if (aCustPrs.get() != NULL)
- aCustPrs->customisePresentation(theAIS);
- }
+
+ customizeObject(theObject);
if (aCanBeShaded) {
openLocalContext();
activateObjects(myActiveSelectionModes);
// before and after the values modification.
// Moreother, this check avoids customize and redisplay presentation if the presentable
// parameter is changed.
- /*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (aResult.get() != NULL) {
Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
if (!aShapePrs.IsNull()) {
return;
}
}
- }*/
- // Customization of presentation
- FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
- if (aFeature.get() != NULL) {
- GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
- if (aCustPrs.get() != NULL)
- aCustPrs->customisePresentation(aAISObj);
}
+ // Customization of presentation
+ customizeObject(theObject);
aContext->Redisplay(aAISIO, false);
if (isUpdateViewer)
}
}
}
+
+void XGUI_Displayer::customizeObject(ObjectPtr theObject)
+{
+ AISObjectPtr anAISObj = getAISObject(theObject);
+ // correct the result's color it it has the attribute
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (aResult.get() != NULL && aResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
+ int aRed, aGreen, aBlue;
+
+ AttributeColorPtr aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(
+ aResult->data()->attribute(ModelAPI_Result::COLOR_ID()));
+ aColorAttr->values(aRed, aGreen, aBlue);
+ anAISObj->setColor(aRed, aGreen, aBlue);
+ }
+ else {
+ // Customization of presentation
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+ if (aFeature.get() != NULL) {
+ GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
+ if (aCustPrs.get() != NULL)
+ aCustPrs->customisePresentation(anAISObj);
+ }
+ }
+}
/// Opens local context. Does nothing if it is already opened.
void openLocalContext();
+ /** Update the object presentable properties such as color, lines width and other
+ * If the object is result with the color attribute value set, it is used,
+ * otherwise the customize is applyed to the object's feature if it is a custom prs
+ * \param theObject an object instance
+ */
+ void customizeObject(ObjectPtr theObject);
+
protected:
/// Reference to workshop
XGUI_Workshop* myWorkshop;
#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 <QtxColorButton.h>
+#include <ModelAPI_AttributeColor.h>
+void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
+{
+ // 1. find the initial value of the color
+ AttributeColorPtr aColorAttr;
+ foreach(ObjectPtr anObj, theObjects) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+ if (aResult.get() != NULL) {
+ AttributePtr anAttr = aResult->data()->attribute(ModelAPI_Result::COLOR_ID());
+ if (anAttr.get() != NULL)
+ aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(anAttr);
+ }
+ }
+ // there is no object with the color attribute
+ if (aColorAttr.get() == NULL)
+ return;
+ int aRed, aGreen, aBlue;
+ aColorAttr->values(aRed, aGreen, aBlue);
+
+ // 2. show the dialog to change the value
+ QDialog aDlg;
+ QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
+
+ QtxColorButton* aColorBtn = new QtxColorButton(&aDlg);
+ aLay->addWidget(aColorBtn);
+ aColorBtn->setColor(QColor(aRed, aGreen, aBlue));
+
+ QPoint aPoint = QCursor::pos();
+ aDlg.move(aPoint);
+
+ bool isDone = aDlg.exec() == QDialog::Accepted;
+ if (!isDone)
+ return;
+
+ QColor aColorResult = aColorBtn->color();
+ int aRedResult = aColorResult.red(),
+ aGreenResult = aColorResult.green(),
+ aBlueResult = aColorResult.blue();
+
+ if (aRedResult == aRed && aGreenResult == aGreen && aBlueResult == aBlue)
+ return;
+
+ // 3. abort the previous operation and start a new one
+ if(!isActiveOperationAborted())
+ return;
+
+ // 4. set the value to all results
+ foreach(ObjectPtr anObj, theObjects) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+ if (aResult.get() != NULL) {
+ AttributePtr anAttr = aResult->data()->attribute(ModelAPI_Result::COLOR_ID());
+ if (anAttr.get() != NULL) {
+ aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(anAttr);
+ if (aColorAttr.get() != NULL)
+ aColorAttr->setValues(aRedResult, aGreenResult, aBlueResult);
+ }
+ }
+ }
+}
+
//**************************************************************
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);