ADD_SUBDIRECTORY (src/PartSetPlugin)
ADD_SUBDIRECTORY (src/ConstructionPlugin)
ADD_SUBDIRECTORY (src/FeaturesPlugin)
+ADD_SUBDIRECTORY (src/SketcherPrs)
ADD_SUBDIRECTORY (src/SketchPlugin)
ADD_SUBDIRECTORY (src/SketchSolver)
ADD_SUBDIRECTORY (src/ModuleBase)
}
}
-void ConstructionPlugin_Axis::customisePresentation(AISObjectPtr thePrs)
+bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
{
- std::vector<int> aRGB = Config_PropManager::color("Visualization", "construction_axis_color",
- ConstructionPlugin_Axis::DEFAULT_COLOR());
- thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
- thePrs->setLineStyle(3);
- thePrs->redisplay();
+ bool isCustomized = theDefaultPrs.get() != NULL &&
+ theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
+
+ isCustomized = thePrs->setLineStyle(3);
+
+ return isCustomized;
}
#include "ConstructionPlugin.h"
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
#include <GeomAPI_ICustomPrs.h>
/**\class ConstructionPlugin_Axis
static const std::string CYLINDRICAL_FACE_ATTR("cylindricalFace");
return CYLINDRICAL_FACE_ATTR;
}
- /// default color for an axis
- inline static const std::string& DEFAULT_COLOR()
- {
- static const std::string CONSTRUCTION_AXIS_COLOR("#000000");
- return CONSTRUCTION_AXIS_COLOR;
- }
inline static const double MINIMAL_LENGTH() { return 1.e-5; }
ConstructionPlugin_Axis();
/// Customize presentation of the feature
- virtual void customisePresentation(AISObjectPtr thePrs);
+ virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
};
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeIntArray.h>
#include <GeomAlgoAPI_FaceBuilder.h>
#include <GeomAPI_Pnt2d.h>
}
}
-void ConstructionPlugin_Plane::customisePresentation(AISObjectPtr thePrs)
+bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
{
- std::vector<int> aRGB = Config_PropManager::color("Visualization", "construction_plane_color",
- ConstructionPlugin_Plane::DEFAULT_COLOR());
- thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
- thePrs->setTransparensy(0.6);
+ std::vector<int> aColor;
+ // get color from the attribute of the result
+ if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
+ AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+ if (aColorAttr.get() && aColorAttr->size()) {
+ aColor.push_back(aColorAttr->value(0));
+ aColor.push_back(aColorAttr->value(1));
+ aColor.push_back(aColorAttr->value(2));
+ }
+ }
+ if (aColor.empty())
+ aColor = Config_PropManager::color("Visualization", "construction_plane_color",
+ ConstructionPlugin_Plane::DEFAULT_COLOR());
+
+ bool isCustomized = false;
+ if (aColor.size() == 3)
+ isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+
+ isCustomized = thePrs->setTransparensy(0.6) || isCustomized;
+
+ return isCustomized;
}
#include "ConstructionPlugin.h"
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
#include <GeomAPI_ICustomPrs.h>
ConstructionPlugin_Plane();
/// Customize presentation of the feature
- virtual void customisePresentation(AISObjectPtr thePrs);
+ virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
};
#endif
ModelAPI_Session::get()->registerPlugin(this);
// register construction properties
- Config_PropManager::registerProp("Visualization", "construction_point_color", "Construction point color",
- Config_Prop::Color, ConstructionPlugin_Point::DEFAULT_COLOR());
- Config_PropManager::registerProp("Visualization", "construction_axis_color", "Construction axis color",
- Config_Prop::Color, ConstructionPlugin_Axis::DEFAULT_COLOR());
Config_PropManager::registerProp("Visualization", "construction_plane_color", "Construction plane color",
Config_Prop::Color, ConstructionPlugin_Plane::DEFAULT_COLOR());
}
aConstr->setShape(GeomAlgoAPI_PointBuilder::point(aPnt));
setResult(aConstr);
}
-
-void ConstructionPlugin_Point::customisePresentation(AISObjectPtr thePrs)
-{
- std::vector<int> aRGB = Config_PropManager::color("Visualization", "construction_point_color",
- ConstructionPlugin_Point::DEFAULT_COLOR());
- thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
- thePrs->redisplay();
-}
#include "ConstructionPlugin.h"
#include <ModelAPI_Feature.h>
-#include <GeomAPI_ICustomPrs.h>
+#include <ModelAPI_Result.h>
/**\class ConstructionPlugin_Point
* \ingroup Plugins
* \brief Feature for creation of the new part in PartSet.
*/
-class ConstructionPlugin_Point : public ModelAPI_Feature, public GeomAPI_ICustomPrs
+class ConstructionPlugin_Point : public ModelAPI_Feature
{
public:
/// Returns the kind of a feature
return CONSTRUCTION_POINT_KIND;
}
- /// default color for a point
- inline static const std::string& DEFAULT_COLOR()
- {
- static const std::string CONSTRUCTION_POINT_COLOR("#ffff00");
- return CONSTRUCTION_POINT_COLOR;
- }
-
/// attribute name for X coordinate
inline static const std::string& X()
{
/// Use plugin manager for features creation
ConstructionPlugin_Point();
-
- /// Modifies the given presentation in the custom way.
- virtual void customisePresentation(AISObjectPtr thePrs);
-
};
#endif
importFile(aFilePath);
}
-void ExchangePlugin_ImportFeature::customisePresentation(AISObjectPtr thePrs)
-{
- std::vector<int> aRGB = Config_PropManager::color("Visualization", "import_feature_color",
- IMPORTED_FEATURE_COLOR);
- thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
- thePrs->redisplay();
-}
-
bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
{
// retrieve the file and plugin library names
#include <ExchangePlugin.h>
#include <ModelAPI_Feature.h>
-
-#include <GeomAPI_ICustomPrs.h>
+#include <ModelAPI_Result.h>
#include <map>
-#define IMPORTED_FEATURE_COLOR "#E0A01B"
-
/**\class ExchangePlugin_ImportFeature
* \ingroup Plugins
* \brief Feature for import shapes from the external files in CAD formats.
*
* The set of supported formats is defined in the configuration file.
*/
-class ExchangePlugin_ImportFeature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
+class ExchangePlugin_ImportFeature : public ModelAPI_Feature
{
public:
/// Extrusion kind
return true;
}
- /// Modifies the given presentation in the custom way.
- virtual void customisePresentation(AISObjectPtr thePrs);
-
protected:
/// POerforms the import of the file
EXCHANGEPLUGIN_EXPORT bool importFile(const std::string& theFileName);
new ExchangePlugin_ImportFormatValidator);
// 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");
+ //Config_PropManager::registerProp("Visualization", "import_feature_color", "Imported feature color",
+ // Config_Prop::Color, ExchangePlugin_ImportFeature::DEFAULT_COLOR());
}
FeaturePtr ExchangePlugin_Plugin::createFeature(string theFeatureID)
GeomAPI_DataMapOfShapeShape.h
GeomAPI_ICustomPrs.h
GeomAPI_Vertex.h
+ GeomAPI_Ax3.h
)
SET(PROJECT_SOURCES
GeomAPI_DataMapOfShapeShape.cpp
GeomAPI_Vertex.cpp
GeomAPI_ICustomPrs.cpp
+ GeomAPI_Ax3.cpp
)
SET(PROJECT_LIBRARIES
#include <AIS_FixRelation.hxx>
#include <Prs3d_PointAspect.hxx>
+#include <Graphic3d_AspectLine3d.hxx>
+
const double tolerance = 1e-7;
const int CONSTRAINT_TEXT_HEIGHT = 28; /// the text height of the constraint
Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
anAspect->MakeArrows3d(Standard_False);
- anAspect->MakeText3d(false);
+ anAspect->MakeText3d(Standard_False);
anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
- anAspect->MakeTextShaded(false);
+ anAspect->MakeTextShaded(Standard_True);
anAspect->ArrowAspect()->SetLength(theDistance / 10.);
aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false);
aDimAIS->SetDimensionAspect(anAspect);
}
}
-void GeomAPI_AISObject::redisplay()
-{
- Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
- if (!anAIS.IsNull()) {
- Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
- aContext->Redisplay(anAIS, false);
- }
-}
-
-
void GeomAPI_AISObject::setColor(const int& theColor)
{
Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
aContext->SetColor(anAIS, aColor, false);
}
-void GeomAPI_AISObject::setWidth(const double& theWidth)
+bool GeomAPI_AISObject::setWidth(const double& theWidth)
{
+ bool isChanged = false;
Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
- if (anAIS.IsNull())
- return;
- anAIS->SetWidth(theWidth);
- anAIS->Redisplay();
+ if (!anAIS.IsNull()) {
+ isChanged = anAIS->Width() != theWidth;
+ if (isChanged)
+ anAIS->SetWidth(theWidth);
+ }
+ return isChanged;
}
-void GeomAPI_AISObject::setColor(int theR, int theG, int theB)
+bool GeomAPI_AISObject::setColor(int theR, int theG, int theB)
{
Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
if (anAIS.IsNull())
- return;
+ return false;
Quantity_Color aColor(theR / 255., theG / 255., theB / 255., Quantity_TOC_RGB);
+ Quantity_Color aCurrentColor;
+ anAIS->Color(aCurrentColor);
+ // do not set the same color to the presentation
+ if (aColor.IsEqual(aCurrentColor))
+ return false;
+
anAIS->SetColor(aColor);
Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS);
if (!aDimAIS.IsNull()) {
}
Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
aContext->SetColor(anAIS, aColor, false);
+ return true;
+}
+
+void GeomAPI_AISObject::getColor(int& theR, int& theG, int& theB)
+{
+ Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+ if (anAIS.IsNull())
+ return;
+
+ Quantity_Color aColor = anAIS->Color();
+ theR = aColor.Red()*255.;
+ theG = aColor.Green()*255.;
+ theB = aColor.Blue()*255.;
}
bool GeomAPI_AISObject::empty() const
}
}
-
-void GeomAPI_AISObject::setLineStyle(int theStyle)
+bool GeomAPI_AISObject::setLineStyle(int theStyle)
{
+ bool isChanged = false;
Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
if (!anAIS.IsNull()) {
Handle(AIS_Drawer) aDrawer = anAIS->Attributes();
- if (aDrawer->HasLineAspect())
- aDrawer->LineAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle);
- if (aDrawer->HasWireAspect())
- aDrawer->WireAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle);
+ Handle(Prs3d_LineAspect) aLineAspect;
+
+ Aspect_TypeOfLine aType = (Aspect_TypeOfLine)theStyle;
+ if (aDrawer->HasLineAspect()) {
+ aLineAspect = aDrawer->LineAspect();
+ }
+ if (aDrawer->HasWireAspect()) {
+ aLineAspect = aDrawer->WireAspect();
+ }
+ Quantity_Color aCurrentColor;
+ Aspect_TypeOfLine aCurrentType;
+ Standard_Real aCurrentWidth;
+ aLineAspect->Aspect()->Values(aCurrentColor, aCurrentType, aCurrentWidth);
+ isChanged = aType != aCurrentType;
+ if (isChanged) {
+ aLineAspect->SetTypeOfLine(aType);
+ }
}
+ return isChanged;
}
-void GeomAPI_AISObject::setTransparensy(double theVal)
+bool GeomAPI_AISObject::setTransparensy(double theVal)
{
+ bool isChanged = false;
Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
if (!anAIS.IsNull()) {
Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
- if (!aContext.IsNull())
- aContext->SetTransparency(anAIS, theVal, false);
+ if (!aContext.IsNull()) {
+ double aCurrentValue = anAIS->Transparency();
+ isChanged = aCurrentValue != theVal;
+ if (isChanged)
+ aContext->SetTransparency(anAIS, theVal, false);
+ }
}
+ return isChanged;
}
void createFixed(std::shared_ptr<GeomAPI_Shape> theShape,
std::shared_ptr<GeomAPI_Pln> thePlane);
- /** \brief Redisplays the current AIS object in the context
- */
- void redisplay();
-
/** \brief Assigns the color for the shape
* \param[in] theColor index of the color
*/
void setColor(const int& theColor);
/** \brief Assigns the color for the shape
+ * \param[in] theR value of the red component
+ * \param[in] theG value of the green component
+ * \param[in] theB value of the blue component
+ * \returns true if the presentation color is changed
+ */
+ bool setColor(int theR, int theG, int theB);
+
+ /** \brief Returns the color for the shape
* \param[in] theR value of the red component
* \param[in] theG value of the green component
* \param[in] theB value of the blue component
*/
- void setColor(int theR, int theG, int theB);
+ void getColor(int& theR, int& theG, int& theB);
/// \brief Assigns the width of the lines of shape
- void setWidth(const double& theWidth);
+ bool setWidth(const double& theWidth);
/// \brief Checks if the object is empty
bool empty() const;
/// Set line type of edges
/// Has to be defined according to Aspect_TypeOfLine
- void setLineStyle(int theStyle);
+ /// \returns true if the object value differs from the current
+ bool setLineStyle(int theStyle);
/// Set transparency of the presentation (theVal = 0 ... 1)
- void setTransparensy(double theVal);
+ /// \returns true if the object value differs from the current
+ bool setTransparensy(double theVal);
};
//! Pointer on attribute object
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomAPI_Ax3.cpp
+// Created: 16 February 2015
+// Author: Vitaly SMETANNIKOV
+
+
+#include "GeomAPI_Ax3.h"
+#include "GeomAPI_XYZ.h"
+#include "GeomAPI_Pnt2d.h"
+
+#include <gp_Dir.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Ax3.hxx>
+#include <Precision.hxx>
+
+
+#define MY_AX3 static_cast<gp_Ax3*>(myImpl)
+
+
+GeomAPI_Ax3::GeomAPI_Ax3()
+: GeomAPI_Interface(new gp_Ax3())
+{
+}
+
+GeomAPI_Ax3::GeomAPI_Ax3(std::shared_ptr<GeomAPI_Pnt> theOrigin,
+ std::shared_ptr<GeomAPI_Dir> theDirX,
+ std::shared_ptr<GeomAPI_Dir> theDirY,
+ std::shared_ptr<GeomAPI_Dir> theNorm)
+: GeomAPI_Interface(new gp_Ax3(theOrigin->impl<gp_Pnt>(),
+ theNorm->impl<gp_Dir>(),
+ theDirX->impl<gp_Dir>()))
+ {
+ MY_AX3->SetYDirection(theDirY->impl<gp_Dir>());
+ }
+
+void GeomAPI_Ax3::setOrigin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin)
+{
+ gp_Ax1 aAx1 = MY_AX3->Axis();
+ aAx1.SetLocation(theOrigin->impl<gp_Pnt>());
+ MY_AX3->SetAxis(aAx1);
+}
+
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::origin() const
+{
+ gp_Pnt aPnt = MY_AX3->Axis().Location();
+ return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPnt.X(),aPnt.Y(),aPnt.Z()));
+}
+
+void GeomAPI_Ax3::setDirX(const std::shared_ptr<GeomAPI_Dir>& theDirX)
+{
+ MY_AX3->SetXDirection(theDirX->impl<gp_Dir>());
+}
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::dirX() const
+{
+ gp_Dir aDir = MY_AX3->XDirection();
+ return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
+}
+
+void GeomAPI_Ax3::setDirY(const std::shared_ptr<GeomAPI_Dir>& theDirY)
+{
+ MY_AX3->SetYDirection(theDirY->impl<gp_Dir>());
+}
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::dirY() const
+{
+ gp_Dir aDir = MY_AX3->YDirection();
+ return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
+}
+
+void GeomAPI_Ax3::setNorm(const std::shared_ptr<GeomAPI_Dir>& theNorm)
+{
+ gp_Ax1 aAx1 = MY_AX3->Axis();
+ aAx1.SetDirection(theNorm->impl<gp_Dir>());
+ MY_AX3->SetAxis(aAx1);
+}
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_Ax3::norm() const
+{
+ gp_Dir aDir = MY_AX3->Axis().Direction();
+ return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(),aDir.Y(),aDir.Z()));
+}
+
+
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ax3::to3D(double theX, double theY) const
+{
+ gp_Pnt aPnt = MY_AX3->Axis().Location();
+ gp_Dir aXDir = MY_AX3->XDirection();
+ gp_Dir aYDir = MY_AX3->YDirection();
+ gp_XYZ aSum = aPnt.XYZ().Added(aXDir.XYZ().Multiplied(theX)).Added(aYDir.XYZ().Multiplied(theY));
+
+ return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum.X(), aSum.Y(), aSum.Z()));
+}
+
+std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Ax3::to2D(double theX, double theY, double theZ) const
+{
+ gp_Pnt anOriginPnt = MY_AX3->Axis().Location();
+ gp_Vec aVec(anOriginPnt, gp_Pnt(0, 0, 0));
+
+ gp_Dir aXDir = MY_AX3->XDirection();
+ gp_Dir aYDir = MY_AX3->YDirection();
+
+ double aX = aVec.X() * aXDir.X() + aVec.Y() * aXDir.Y() + aVec.Z() * aXDir.Z();
+ double aY = aVec.X() * aYDir.X() + aVec.Y() * aYDir.Y() + aVec.Z() * aYDir.Y();
+ return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomAPI_Ax3.hxx
+// Created: 16 February 2015
+// Author: Vitaly SMETANNIKOV
+
+#ifndef GEOMAPI_AX3_H_
+#define GEOMAPI_AX3_H_
+
+#include "GeomAPI.h"
+#include "GeomAPI_Pnt.h"
+#include "GeomAPI_Dir.h"
+
+/**
+ * \ingroup DataModel
+ * \brief The class represents a coordinate plane which is 2d plane with X and Y directions
+ * and origin
+ */
+class GEOMAPI_EXPORT GeomAPI_Ax3 : public GeomAPI_Interface
+{
+public:
+ /// Default constructor
+ GeomAPI_Ax3();
+
+ /// Ñonstructor
+ /// \param theOrigin point of origin
+ /// \param theDirX direction of X axis
+ /// \param theDirY direction of Y axis
+ /// \param theNorm direction of normal vector
+ GeomAPI_Ax3(std::shared_ptr<GeomAPI_Pnt> theOrigin,
+ std::shared_ptr<GeomAPI_Dir> theDirX,
+ std::shared_ptr<GeomAPI_Dir> theDirY,
+ std::shared_ptr<GeomAPI_Dir> theNorm);
+
+ /// Sets origin point
+ void setOrigin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin);
+
+ /// Returns the plane origin point
+ std::shared_ptr<GeomAPI_Pnt> origin() const;
+
+ /// Sets X direction vector
+ void setDirX(const std::shared_ptr<GeomAPI_Dir>& theDirX);
+
+ /// Returns X direction vector
+ std::shared_ptr<GeomAPI_Dir> dirX() const;
+
+ /// Sets Y direction vector
+ void setDirY(const std::shared_ptr<GeomAPI_Dir>& theDirY);
+
+ /// Returns Y direction vector
+ std::shared_ptr<GeomAPI_Dir> dirY() const;
+
+ /// Sets Z direction vector
+ void setNorm(const std::shared_ptr<GeomAPI_Dir>& theNorm);
+
+ /// Returns Z direction vector
+ std::shared_ptr<GeomAPI_Dir> norm() const;
+
+ /// Converts 2d coordinates from the plane to 3d space point
+ /// \param theX X coordinate
+ /// \param theY Y coordinate
+ std::shared_ptr<GeomAPI_Pnt> to3D(double theX, double theY) const;
+
+ /// Converts 3d to 2d coordinates of the plane
+ /// \param theX X coordinate
+ /// \param theY Y coordinate
+ /// \param theZ Z coordinate
+ std::shared_ptr<GeomAPI_Pnt2d> to2D(double theX, double theY, double theZ) const;
+
+};
+
+
+#endif
\ No newline at end of file
#include "GeomAPI.h"
#include "GeomAPI_AISObject.h"
+#include "GeomAPI_AISObject.h"
+#include <vector>
/**
* Interface of a class which can provide specific customization of
* object presentation
*/
+class ModelAPI_Result;
+
class GeomAPI_ICustomPrs
{
public:
GEOMAPI_EXPORT virtual ~GeomAPI_ICustomPrs();
/// Modifies the given presentation in the custom way.
- virtual void customisePresentation(AISObjectPtr thePrs) = 0;
+ virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs) = 0;
};
typedef std::shared_ptr<GeomAPI_ICustomPrs> GeomCustomPrsPtr;
}
bool GeomAPI_PlanarEdges::hasPlane() const {
- return myOrigin && myNorm && myDirX && myDirY;
+ return myPlane.get() != NULL;
}
bool GeomAPI_PlanarEdges::isVertex() const {
return false;
}
-void GeomAPI_PlanarEdges::setOrigin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin)
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_PlanarEdges::origin() const
{
- myOrigin = theOrigin;
+ if (hasPlane())
+ return myPlane->origin();
+ return std::shared_ptr<GeomAPI_Pnt>();
}
-std::shared_ptr<GeomAPI_Pnt> GeomAPI_PlanarEdges::origin() const {
- return myOrigin;
-}
-void GeomAPI_PlanarEdges::setDirX(const std::shared_ptr<GeomAPI_Dir>& theDirX) {
- myDirX = theDirX;
-}
-std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirX() const {
- return myDirX;
-}
-void GeomAPI_PlanarEdges::setDirY(const std::shared_ptr<GeomAPI_Dir>& theDirY) {
- myDirY = theDirY;
-}
-std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirY() const {
- return myDirY;
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirX() const
+{
+ if (hasPlane())
+ return myPlane->dirX();
+ return std::shared_ptr<GeomAPI_Dir>();
}
-void GeomAPI_PlanarEdges::setNorm(const std::shared_ptr<GeomAPI_Dir>& theNorm) {
- myNorm = theNorm;
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::dirY() const
+{
+ if (hasPlane())
+ return myPlane->dirY();
+ return std::shared_ptr<GeomAPI_Dir>();
}
-std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::norm() const {
- return myNorm;
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::norm() const
+{
+ if (hasPlane())
+ return myPlane->norm();
+ return std::shared_ptr<GeomAPI_Dir>();
}
+
+void GeomAPI_PlanarEdges::setPlane(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
+ const std::shared_ptr<GeomAPI_Dir>& theDirX,
+ const std::shared_ptr<GeomAPI_Dir>& theDirY,
+ const std::shared_ptr<GeomAPI_Dir>& theNorm)
+{
+ myPlane = std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(theOrigin, theDirX, theDirY, theNorm));
+}
\ No newline at end of file
#include "GeomAPI_Edge.h"
#include "GeomAPI_Pnt.h"
#include "GeomAPI_Dir.h"
+#include "GeomAPI_Ax3.h"
#include <memory>
/// Returns True if the wire is defined in a plane
GEOMAPI_EXPORT bool hasPlane() const;
- /// Sets origin point
- GEOMAPI_EXPORT void setOrigin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin);
-
/// Returns the plane origin point
GEOMAPI_EXPORT std::shared_ptr<GeomAPI_Pnt> origin() const;
- /// Sets X direction vector
- GEOMAPI_EXPORT void setDirX(const std::shared_ptr<GeomAPI_Dir>& theDirX);
/// Returns X direction vector
GEOMAPI_EXPORT std::shared_ptr<GeomAPI_Dir> dirX() const;
- /// Sets Y direction vector
- GEOMAPI_EXPORT void setDirY(const std::shared_ptr<GeomAPI_Dir>& theDirY);
/// Returns Y direction vector
GEOMAPI_EXPORT std::shared_ptr<GeomAPI_Dir> dirY() const;
- /// Sets Z direction vector
- GEOMAPI_EXPORT void setNorm(const std::shared_ptr<GeomAPI_Dir>& theNorm);
/// Returns Z direction vector
GEOMAPI_EXPORT std::shared_ptr<GeomAPI_Dir> norm() const;
+ /// Set working plane
+ /// \param theOrigin origin of the plane axis
+ /// \param theDirX X direction of the plane axis
+ /// \param theDirY Y direction of the plane axis
+ /// \param theNorm normal direction of the plane axis
+ GEOMAPI_EXPORT void setPlane(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
+ const std::shared_ptr<GeomAPI_Dir>& theDirX,
+ const std::shared_ptr<GeomAPI_Dir>& theDirY,
+ const std::shared_ptr<GeomAPI_Dir>& theNorm);
+
private:
- /// Origin point of the plane
- std::shared_ptr<GeomAPI_Pnt> myOrigin;
- /// The X direction inside of the plane
- std::shared_ptr<GeomAPI_Dir> myDirX;
- /// The Y direction inside of the plane
- std::shared_ptr<GeomAPI_Dir> myDirY;
- /// The normal direction to the plane
- std::shared_ptr<GeomAPI_Dir> myNorm;
+
+ std::shared_ptr<GeomAPI_Ax3> myPlane;
};
#endif
if (nbSubResults == 1) {
itr.Initialize(theResult);
if (itr.More()) aResult = itr.Value();
+ } else {
+ /// MPV: store compound anyway: it may be Boolean operation that produces two solids from one
+ aResult = theResult;
}
}
return aResult;
Model_AttributeRefAttr.h
Model_AttributeRefList.h
Model_AttributeBoolean.h
- Model_AttributeColor.h
+ Model_AttributeIntArray.h
Model_AttributeString.h
Model_AttributeInteger.h
Model_AttributeSelection.h
Model_AttributeRefAttr.cpp
Model_AttributeRefList.cpp
Model_AttributeBoolean.cpp
- Model_AttributeColor.cpp
+ Model_AttributeIntArray.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
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: Model_AttributeIntArray.cpp
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#include <Model_AttributeIntArray.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>
+
+int Model_AttributeIntArray::size()
+{
+ return myArray.IsNull() ? 0 : myArray->Length();
+}
+
+void Model_AttributeIntArray::setSize(const int theSize)
+{
+ if (myArray.IsNull()) { // create array if it is not done yet
+ if (theSize != 0) { // if size is zero, nothing to do (null array means there is no array)
+ myArray = TDataStd_IntegerArray::Set(myLab, 0, theSize);
+ owner()->data()->sendAttributeUpdated(this);
+ }
+ } else { // reset the old array
+ if (theSize) {
+ if (theSize != myArray->Length()) { // old data is not keept, a new array is created
+ Handle(TColStd_HArray1OfInteger) aNewArray = new TColStd_HArray1OfInteger(0, theSize - 1);
+ myArray->ChangeArray(aNewArray);
+ owner()->data()->sendAttributeUpdated(this);
+ }
+ } else { // size is zero => array must be erased
+ if (!myArray.IsNull()) {
+ myArray.Nullify();
+ myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
+ owner()->data()->sendAttributeUpdated(this);
+ }
+ }
+ }
+}
+
+void Model_AttributeIntArray::setValue(const int theIndex,
+ const int theValue)
+{
+ if (myArray->Value(theIndex) != theValue) {
+ myArray->SetValue(theIndex, theValue);
+ owner()->data()->sendAttributeUpdated(this);
+ }
+}
+
+int Model_AttributeIntArray::value(const int theIndex)
+{
+ return myArray->Value(theIndex);
+}
+
+Model_AttributeIntArray::Model_AttributeIntArray(TDF_Label& theLabel)
+{
+ myLab = theLabel;
+ // check the attribute could be already presented in this doc (after load document)
+ myIsInitialized =
+ myLab.FindAttribute(TDataStd_IntegerArray::GetID(), myArray) == Standard_True;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: Model_AttributeIntArray.h
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef MODEL_ATTRIBUTEINTARRAY_H_
+#define MODEL_ATTRIBUTEINTARRAY_H_
+
+#include <Model.h>
+#include <ModelAPI_AttributeIntArray.h>
+
+#include <TDF_Label.hxx>
+#include <TDataStd_IntegerArray.hxx>
+
+#include <string>
+
+/**\class Model_AttributeIntArray
+ * \ingroup DataModel
+ * \brief API for the attribute that contains several integers in the array inside.
+ * Used for RGB color storage for an example. By default size is one, zero-based.
+ * Represented as array in OCCT. Empty array means that this attribute does not exists.
+ */
+
+class Model_AttributeIntArray : public ModelAPI_AttributeIntArray
+{
+ /// The OCCT array that keeps all values.
+ Handle_TDataStd_IntegerArray myArray;
+ /// Stores the label as a field to set array if size is not null (null array is buggy in OCAF)
+ TDF_Label myLab;
+ public:
+
+ /// Returns the size of the array (zero means that it is empty)
+ MODEL_EXPORT virtual int size();
+
+ /// Sets the new size of the array. The previous data is erased.
+ MODEL_EXPORT virtual void setSize(const int theSize);
+
+ /// Defines the value of the array by index [0; size-1]
+ MODEL_EXPORT virtual void setValue(const int theIndex,
+ const int theValue);
+
+ /// Returns the value by the index
+ MODEL_EXPORT virtual int value(const int theIndex);
+
+
+ protected:
+ /// Initializes attibutes
+ Model_AttributeIntArray(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_AttributeIntArray.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);
+ } else if (theAttrType == ModelAPI_AttributeIntArray::type()) {
+ anAttr = new Model_AttributeIntArray(anAttrLab);
}
// create also GeomData attributes here because only here the OCAF strucure is known
else if (theAttrType == GeomData_Point::type()) {
GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelectionList, selectionList);
GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr);
GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray);
std::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
{
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Object.h>
/// Returns the attribute that contains real value with double precision
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeString>
string(const std::string& theID);
+ /// Returns the attribute that contains integer values array
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeIntArray>
+ intArray(const std::string& theID);
+
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID);
#include <Model_ResultBody.h>
#include <Model_Data.h>
#include <Model_Document.h>
-#include <ModelAPI_AttributeColor.h>
+#include <ModelAPI_AttributeIntArray.h>
#include <TNaming_Builder.hxx>
#include <TNaming_NamedShape.hxx>
#include <TDataStd_Name.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
+ // append the color attribute. It is empty, the attribute will be filled by a request
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]);
- }
+ aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type());
+}
+
+void Model_ResultBody::colorConfigInfo(std::string& theSection, std::string& theName,
+ std::string& theDefault)
+{
+ theSection = "Visualization";
+ theName = "result_body_color";
+ theDefault = DEFAULT_COLOR();
}
void Model_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
/// label; index in vector corresponds to the label tag
std::vector<TNaming_Builder*> myBuilders;
public:
+ /// default color for a result body
+ inline static const std::string& DEFAULT_COLOR()
+ {
+ static const std::string RESULT_BODY_COLOR("#E0A01B");
+ return RESULT_BODY_COLOR;
+ }
+
/// Request for initialization of data model of the result: adding all attributes
virtual void initAttributes();
+ // Retuns the parameters of color definition in the resources config manager
+ MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
+ std::string& theDefault);
+
/// Stores the shape (called by the execution method).
MODEL_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape);
#include <Model_ResultConstruction.h>
+#include <ModelAPI_AttributeIntArray.h>
+#include <Config_PropManager.h>
+
+void Model_ResultConstruction::initAttributes()
+{
+ // append the color attribute. It is empty, the attribute will be filled by a request
+ DataPtr aData = data();
+ aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type());
+}
+
+void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::string& theName,
+ std::string& theDefault)
+{
+ theSection = "Visualization";
+ theName = "result_construction_color";
+ theDefault = DEFAULT_COLOR();
+}
+
void Model_ResultConstruction::setShape(std::shared_ptr<GeomAPI_Shape> theShape)
{
myShape = theShape;
std::shared_ptr<GeomAPI_Shape> myShape; ///< shape of this result created "on the fly"
bool myIsInHistory;
public:
+ /// default color for a result construction
+ inline static const std::string& DEFAULT_COLOR()
+ {
+ static const std::string RESULT_CONSTRUCTION_COLOR("#000000");
+ return RESULT_CONSTRUCTION_COLOR;
+ }
+
+ /// Request for initialization of data model of the result: adding all attributes
+ virtual void initAttributes();
+
+ // Retuns the parameters of color definition in the resources config manager
+ MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
+ std::string& theDefault);
+
/// By default object is displayed in the object browser.
MODEL_EXPORT virtual bool isInHistory()
{
#include <Model_ResultGroup.h>
#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeIntArray.h>
+
#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <Config_PropManager.h>
+
Model_ResultGroup::Model_ResultGroup(std::shared_ptr<ModelAPI_Data> theOwnerData)
{
setIsConcealed(false);
myOwnerData = theOwnerData;
}
+void Model_ResultGroup::initAttributes()
+{
+ // append the color attribute. It is empty, the attribute will be filled by a request
+ DataPtr aData = data();
+ aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type());
+}
+
+void Model_ResultGroup::colorConfigInfo(std::string& theSection, std::string& theName,
+ std::string& theDefault)
+{
+ theSection = "Visualization";
+ theName = "result_group_color";
+ theDefault = DEFAULT_COLOR();
+}
+
std::shared_ptr<GeomAPI_Shape> Model_ResultGroup::shape()
{
std::shared_ptr<GeomAPI_Shape> aResult;
{
std::shared_ptr<ModelAPI_Data> myOwnerData; ///< data of owner of this result
public:
+ /// default color for a result body
+ inline static const std::string& DEFAULT_COLOR()
+ {
+ static const std::string RESULT_GROUP_COLOR("#E0A01B");
+ return RESULT_GROUP_COLOR;
+ }
+ /// Request for initialization of data model of the result: adding all attributes
+ virtual void initAttributes();
+
+ // Retuns the parameters of color definition in the resources config manager
+ MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
+ std::string& theDefault);
+
/// Returns the compound of selected entities
MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shape();
ModelAPI.h
ModelAPI_Attribute.h
ModelAPI_AttributeBoolean.h
- ModelAPI_AttributeColor.h
+ ModelAPI_AttributeIntArray.h
ModelAPI_AttributeDocRef.h
ModelAPI_AttributeDouble.h
ModelAPI_AttributeInteger.h
SET(PROJECT_SOURCES
ModelAPI_Attribute.cpp
ModelAPI_AttributeBoolean.cpp
- ModelAPI_AttributeColor.cpp
+ ModelAPI_AttributeIntArray.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
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModelAPI_AttributeIntArray.cpp
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#include <ModelAPI_AttributeIntArray.h>
+
+
+std::string ModelAPI_AttributeIntArray::attributeType()
+{
+ return type();
+}
+
+/// To virtually destroy the fields of successors
+ModelAPI_AttributeIntArray::~ModelAPI_AttributeIntArray()
+{
+}
+
+ModelAPI_AttributeIntArray::ModelAPI_AttributeIntArray()
+{
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModelAPI_AttributeIntArray.h
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModelAPI_AttributeIntArray_H_
+#define ModelAPI_AttributeIntArray_H_
+
+#include <ModelAPI.h>
+#include <ModelAPI_Attribute.h>
+
+#include <string>
+
+
+/**\class ModelAPI_AttributeIntArray
+ * \ingroup DataModel
+ * \brief API for the attribute that contains several integers in the array inside.
+ * Used for RGB color storage for an example. By default size is one, zero-based.
+ */
+
+class ModelAPI_AttributeIntArray : public ModelAPI_Attribute
+{
+ public:
+
+ /// Returns the size of the array (zero means that it is empty)
+ MODELAPI_EXPORT virtual int size() = 0;
+
+ /// Sets the new size of the array. The previous data is erased.
+ MODELAPI_EXPORT virtual void setSize(const int theSize) = 0;
+
+ /// Defines the value of the array by index [0; size-1]
+ MODELAPI_EXPORT virtual void setValue(const int theIndex,
+ const int theValue) = 0;
+
+ /// Returns the value by the index
+ MODELAPI_EXPORT virtual int value(const int theIndex) = 0;
+
+ /// Returns the type of this class of attributes
+ MODELAPI_EXPORT static std::string type()
+ {
+ return "IntArray";
+ }
+
+ /// 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_AttributeIntArray();
+
+ protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_AttributeIntArray();
+};
+
+//! Pointer on double attribute
+typedef std::shared_ptr<ModelAPI_AttributeIntArray> AttributeIntArrayPtr;
+
+#endif
class ModelAPI_Feature;
class ModelAPI_AttributeSelection;
class ModelAPI_AttributeSelectionList;
+class ModelAPI_AttributeIntArray;
class ModelAPI_Object;
class GeomAPI_Shape;
virtual std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID) = 0;
/// Returns the attribute that contains boolean value
virtual std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID) = 0;
+ /// Returns the attribute that contains integer values array
+ virtual std::shared_ptr<ModelAPI_AttributeIntArray> intArray(const std::string& theID) = 0;
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
myIsConcealed = theValue;
}
+ // Retuns the parameters of color definition in the resources config manager
+ virtual void colorConfigInfo(std::string& theSection, std::string& theName, std::string& theDefault) {}
+
/// Request for initialization of data model of the result: adding all attributes
virtual void initAttributes() {};
#include "ModuleBase_Preferences.h"
//#include "ModuleBase_Constants.h"
+#include <Model_ResultBody.h>
+#include <Model_ResultGroup.h>
+#include <Model_ResultConstruction.h>
+
#include <Config_PropManager.h>
#include <SUIT_ResourceMgr.h>
myPreferences->setItemProperty("texture_stretch_enabled", true, bgId);
myPreferences->setItemProperty("custom_enabled", false, bgId);
myPreferences->setItemProperty("image_formats", aImgFiles, bgId);
+
+ //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
+ // Config_Prop::Color, "#ffffff");
+
+ Config_PropManager::registerProp("Visualization", "result_body_color", "Body color",
+ Config_Prop::Color, Model_ResultBody::DEFAULT_COLOR());
+ Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
+ Config_Prop::Color, Model_ResultGroup::DEFAULT_COLOR());
+ Config_PropManager::registerProp("Visualization", "result_construction_color", "Construction color",
+ Config_Prop::Color, Model_ResultConstruction::DEFAULT_COLOR());
}
void ModuleBase_PreferencesDlg::createMenuPage(int thePageId)
GeomAPI
GeomAlgoAPI
ModelAPI
+ SketcherPrs
${CAS_KERNEL}
${CAS_SHAPE}
)
../GeomAPI
../GeomAlgoAPI
../GeomDataAPI
+ ../SketcherPrs
)
INSTALL(TARGETS SketchPlugin DESTINATION plugins)
#include "SketchPlugin_ConstraintCoincidence.h"
+#include <SketcherPrs_Factory.h>
+
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
#include <SketchPlugin_Point.h>
+#include <GeomDataAPI_Dir.h>
+#include <GeomDataAPI_Point.h>
SketchPlugin_ConstraintCoincidence::SketchPlugin_ConstraintCoincidence()
{
{
}
+AISObjectPtr SketchPlugin_ConstraintCoincidence::getAISObject(AISObjectPtr thePrevious)
+{
+ if (!sketch())
+ return thePrevious;
+
+ AISObjectPtr anAIS = thePrevious;
+ if (!anAIS) {
+ anAIS = SketcherPrs_Factory::coincidentConstraint(this, sketch()->coordinatePlane());
+ anAIS->setColor(0, 0, 255);
+ }
+ return anAIS;
+}
\ No newline at end of file
return MY_KIND;
}
+ /// Returns the AIS preview
+ SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
// Author: Artem ZHIDKOV
#include "SketchPlugin_ConstraintParallel.h"
-#include "SketchPlugin_ConstraintPerpendicular.h"
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Sketch.h>
+#include <SketcherPrs_Factory.h>
+
#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Pnt.h>
+#include <GeomDataAPI_Dir.h>
+#include <GeomDataAPI_Point.h>
#include <Config_PropManager.h>
{
data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type());
- data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type());
+ //data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type());
}
void SketchPlugin_ConstraintParallel::execute()
if (!sketch())
return thePrevious;
- std::shared_ptr<ModelAPI_Data> aData = data();
- std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 = std::dynamic_pointer_cast<
- ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
- std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 = std::dynamic_pointer_cast<
- ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
- if (!anAttr1 || !anAttr1->isObject() || !anAttr2 || !anAttr2->isObject())
- return thePrevious;
-
- FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr1->object());
- if (!aFeature)
- return thePrevious;
- std::shared_ptr<SketchPlugin_Line> aLine1Feature =
- std::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
-
- aFeature = ModelAPI_Feature::feature(anAttr2->object());
- if (!aFeature)
- return thePrevious;
- std::shared_ptr<SketchPlugin_Line> aLine2Feature =
- std::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
-
- if (!aLine1Feature || !aLine2Feature)
- return thePrevious;
-
- std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
- std::shared_ptr<GeomAPI_Shape> aLine1, aLine2;
- std::shared_ptr<ModelAPI_ResultConstruction> aConst1 = std::dynamic_pointer_cast<
- ModelAPI_ResultConstruction>(anAttr1->object());
- if (aConst1)
- aLine1 = aConst1->shape();
- std::shared_ptr<ModelAPI_ResultConstruction> aConst2 = std::dynamic_pointer_cast<
- ModelAPI_ResultConstruction>(anAttr2->object());
- if (aConst2)
- aLine2 = aConst2->shape();
-
- std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
- std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = std::shared_ptr<GeomAPI_Pnt>();;
- if(aFlyoutAttr->isInitialized()) {
- aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
- }
-
AISObjectPtr anAIS = thePrevious;
- if (!anAIS)
- anAIS = AISObjectPtr(new GeomAPI_AISObject);
- anAIS->createParallel(aLine1, aLine2, aFlyoutPnt, aPlane);
-
- // Set color from preferences
- std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_parallel_color",
- SKETCH_CONSTRAINT_COLOR);
- anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
+ if (!anAIS) {
+ anAIS = SketcherPrs_Factory::parallelConstraint(this, sketch()->coordinatePlane());
+ }
return anAIS;
}
-void SketchPlugin_ConstraintParallel::move(double theDeltaX, double theDeltaY)
-{
- std::shared_ptr<ModelAPI_Data> aData = data();
- if (!aData->isValid())
- return;
-
- std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
- aPoint->move(theDeltaX, theDeltaY);
-}
/// Moves the feature
/// \param theDeltaX the delta for X coordinate is moved
/// \param theDeltaY the delta for Y coordinate is moved
- SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+ //SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
/// \brief Use plugin manager for features creation
SketchPlugin_ConstraintParallel();
for (; aShapeIt != aFeaturesPreview.end(); ++aShapeIt) {
aBigWire->addEdge(*aShapeIt);
}
- aBigWire->setOrigin(anOrigin->pnt());
- aBigWire->setDirX(aDirX->dir());
- aBigWire->setDirY(aDirY->dir());
- aBigWire->setNorm(aNorm->dir());
+ aBigWire->setPlane(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir());
// GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(),
// aFeaturesPreview, aLoops, aWires);
return std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir()));
}
+std::shared_ptr<GeomAPI_Ax3> SketchPlugin_Sketch::coordinatePlane() const
+{
+ DataPtr aData = data();
+ std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+
+ return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(aC->pnt(), aX->dir(), aY->dir(), aNorm->dir()));
+}
+
void SketchPlugin_Sketch::erase()
{
std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Pln.h>
#include <GeomAPI_IPresentable.h>
+#include <GeomAPI_Ax3.h>
#include <list>
#define YZ_PLANE_COLOR "#ff0000"
SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY)
{
}
- ;
/// Return the distance between the feature and the point
/// \param thePoint the point
{
return 0;
}
- ;
/// Converts a 2D sketch space point into point in 3D space
SKETCHPLUGIN_EXPORT std::shared_ptr<GeomAPI_Pnt> to3D(const double theX, const double theY);
/// Returns the basis plane for the sketch
std::shared_ptr<GeomAPI_Pln> plane();
+ SKETCHPLUGIN_EXPORT std::shared_ptr<GeomAPI_Ax3> coordinatePlane() const;
+
//virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
/// removes also all sub-sketch elements
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
+#include <ModelAPI_AttributeIntArray.h>
SketchPlugin_SketchEntity::SketchPlugin_SketchEntity()
: SketchPlugin_Feature()
}
/// Customize presentation of the feature
- virtual void customisePresentation(AISObjectPtr thePrs)
+ virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
{
- std::vector<int> aRGB;
-
+ bool isCustomized = false;
int aShapeType = thePrs->getShapeType();
- if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
- return;
+ // a compound is processed like the edge because the arc feature uses the compound for presentable AIS
+ if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/ && aShapeType != 0/*compound*/)
+ return false;
+ std::vector<int> aColor;
std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
- data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID());
+ data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID());
bool isConstruction = aConstructionAttr.get() != NULL && aConstructionAttr->value();
- if (aShapeType == 6) { // if this is an edge
+ if (aShapeType == 6 || aShapeType == 0) { // if this is an edge or a compound
if (isConstruction) {
- thePrs->setWidth(1);
- thePrs->setLineStyle(3);
- aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
- SKETCH_CONSTRUCTION_COLOR);
+ isCustomized = thePrs->setWidth(1) || isCustomized;
+ isCustomized = thePrs->setLineStyle(3) || isCustomized;
+
+ aColor = Config_PropManager::color("Visualization", "sketch_construction_color",
+ SKETCH_CONSTRUCTION_COLOR);
}
else {
- thePrs->setWidth(3);
- thePrs->setLineStyle(0);
+ isCustomized = thePrs->setWidth(3) || isCustomized;
+ isCustomized = thePrs->setLineStyle(0) || isCustomized;
+
if (isExternal()) {
// Set color from preferences
- aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
- SKETCH_EXTERNAL_EDGE_COLOR);
+ aColor = 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);
+ aColor = 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);
+ aColor = Config_PropManager::color("Visualization", "sketch_point_color",
+ SKETCH_POINT_COLOR);
}
- if (!aRGB.empty())
- thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
+ if (!aColor.empty()) {
+ isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]) || isCustomized;
+ }
+ return isCustomized;
}
protected:
</feature>
<feature id="SketchPoint" title="Point" tooltip="Create a new point" icon=":icons/point.png">
<sketch-2dpoint_selector id="PointCoordindates" title="Point" tooltip="Point coordinates"/>
+ <boolvalue id="Construction" label="Construction" default="false" tooltip="Construction element" obligatory="0"/>
</feature>
<feature id="SketchLine" title="Line" tooltip="Create a new line" icon=":icons/line.png">
<sketch-2dpoint_selector id="StartPoint" title="Start point" tooltip="Start point coordinates" previous_feature_param="EndPoint"/>
<point2ddistance id="CircleRadius" first_point="CircleCenter" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set radius">
<validator id="GeomValidators_Positive"/>
</point2ddistance>
+ <boolvalue id="Construction" label="Construction" default="false" tooltip="Construction element" obligatory="0"/>
</feature>
<feature id="SketchArc" title="Arc" tooltip="Create a new arc" icon=":icons/arc.png">
<sketch-2dpoint_selector id="ArcCenter" title="Center" tooltip="Center of a circle"/>
<sketch-2dpoint_selector id="ArcStartPoint" title="Start point" tooltip="Start point"/>
<sketch-2dpoint_selector id="ArcEndPoint" title="End point" tooltip="End point"/>
+ <boolvalue id="Construction" label="Construction" default="false" tooltip="Construction element" obligatory="0"/>
</feature>
</group>
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
</sketch_constraint_shape_selector>
- <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" internal="1" obligatory="0"/>
<validator id="PartSet_ParallelValidator"/>
</feature>
<!-- SketchConstraintPerpendicular -->
--- /dev/null
+## Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+SET(PROJECT_HEADERS
+ SketcherPrs.h
+ SketcherPrs_Coincident.h
+ SketcherPrs_Factory.h
+ SketcherPrs_Parallel.h
+ SketcherPrs_Tools.h
+)
+
+SET(PROJECT_SOURCES
+ SketcherPrs_Coincident.cpp
+ SketcherPrs_Factory.cpp
+ SketcherPrs_Parallel.cpp
+ SketcherPrs_Tools.cpp
+)
+
+SET(PROJECT_LIBRARIES
+ Config
+ ModelAPI
+ GeomAPI
+ ${CAS_KERNEL}
+ ${CAS_MODELER}
+ ${CAS_VIEWER}
+ ${CAS_SHAPE}
+ ${CAS_TKTopAlgo}
+)
+
+SET(PROJECT_PICTURES
+ icons/parallel.png
+)
+
+ADD_DEFINITIONS(-DCONSTRAINTS_EXPORTS ${CAS_DEFINITIONS})
+ADD_LIBRARY(SketcherPrs SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+
+INCLUDE_DIRECTORIES(
+ ${PROJECT_SOURCE_DIR}/src/Config
+ ${PROJECT_SOURCE_DIR}/src/ModelAPI
+ ${PROJECT_SOURCE_DIR}/src/GeomAPI
+ ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
+ ${PROJECT_SOURCE_DIR}/src/SketchPlugin
+ ${CAS_INCLUDE_DIRS}
+)
+
+TARGET_LINK_LIBRARIES(SketcherPrs ${PROJECT_LIBRARIES})
+
+INSTALL(TARGETS SketcherPrs DESTINATION bin)
+INSTALL(FILES ${PROJECT_PICTURES} DESTINATION resources)
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef SKETCHERPRS_H
+#define SKETCHERPRS_H
+
+#if defined SKETCHERPRS_EXPORTS
+#if defined WIN32
+#define SKETCHERPRS_EXPORT __declspec( dllexport )
+#else
+#define SKETCHERPRS_EXPORT
+#endif
+#else
+#if defined WIN32
+#define SKETCHERPRS_EXPORT __declspec( dllimport )
+#else
+#define SKETCHERPRS_EXPORT
+#endif
+#endif
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Coincident.cpp
+// Created: 12 February 2015
+// Author: Vitaly SMETANNIKOV
+
+#include "SketcherPrs_Coincident.h"
+#include "SketcherPrs_Tools.h"
+
+#include <ModelAPI_AttributeRefAttr.h>
+#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Dir.h>
+#include <GeomDataAPI_Point.h>
+
+#include <GeomAPI_XYZ.h>
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_Pnt2d.h>
+
+#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Constraint.h>
+
+#include <AIS_Drawer.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+#include <Graphic3d_ArrayOfPoints.hxx>
+#include <Prs3d_PointAspect.hxx>
+#include <Prs3d_Root.hxx>
+
+
+IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject);
+IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject);
+
+SketcherPrs_Coincident::SketcherPrs_Coincident(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+ : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
+{
+}
+
+
+
+void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
+{
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint,
+ SketchPlugin_Constraint::ENTITY_A());
+ if (aPnt.get() == NULL)
+ return;
+
+ std::shared_ptr<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y());
+
+ static Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d ();
+ aPtA->SetType(Aspect_TOM_RING1);
+ aPtA->SetScale(2.);
+ aPtA->SetColor(myOwnColor);
+ Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
+ aGroup->SetPrimitivesAspect(aPtA);
+ Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
+ aPntArray->AddVertex (aPoint->x(), aPoint->y(), aPoint->z());
+ aGroup->AddPrimitiveArray (aPntArray);
+}
+
+
+void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+ const Standard_Integer aMode)
+{
+}
+
+void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
+{
+ SetColor(Quantity_Color(aCol));
+}
+
+void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol)
+{
+ hasOwnColor=Standard_True;
+ myOwnColor=aCol;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Coincident.h
+// Created: 12 February 2015
+// Author: Vitaly SMETANNIKOV
+
+#ifndef SketcherPrs_Coincident_H
+#define SketcherPrs_Coincident_H
+
+#include <GeomAPI_Ax3.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <Standard_DefineHandle.hxx>
+
+class SketchPlugin_Constraint;
+
+
+DEFINE_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject)
+
+/**
+* \ingroup GUI
+* A redefinition of standard AIS Interactive Object in order to provide
+* presentation of coincident constraint
+*/
+class SketcherPrs_Coincident: public AIS_InteractiveObject
+{
+public:
+ /// Constructor
+ /// \param theResult a result object
+ Standard_EXPORT SketcherPrs_Coincident(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
+ Standard_EXPORT virtual void SetColor(const Quantity_Color& aColor);
+
+ Standard_EXPORT virtual void SetColor(const Quantity_NameOfColor aColor);
+
+ DEFINE_STANDARD_RTTI(SketcherPrs_Coincident)
+protected:
+ /// Redefinition of virtual function
+ Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
+
+ /// Redefinition of virtual function
+ Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+ const Standard_Integer aMode) ;
+
+private:
+ SketchPlugin_Constraint* myConstraint;
+ std::shared_ptr<GeomAPI_Ax3> myPlane;
+};
+
+
+#endif
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Factory.cpp
+// Created: 13 February 2015
+// Author: Vitaly SMETANNIKOV
+
+#include "SketcherPrs_Factory.h"
+
+#include <SketcherPrs_Coincident.h>
+#include <SketcherPrs_Parallel.h>
+
+
+AISObjectPtr SketcherPrs_Factory::coincidentConstraint(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+{
+ std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+ Handle(SketcherPrs_Coincident) aPrs = new SketcherPrs_Coincident(theConstraint, thePlane);
+ aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
+ return aAISObj;
+}
+
+
+AISObjectPtr SketcherPrs_Factory::parallelConstraint(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+{
+ std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+ Handle(SketcherPrs_Parallel) aPrs = new SketcherPrs_Parallel(theConstraint, thePlane);
+ aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
+ return aAISObj;
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Factory.h
+// Created: 13 February 2015
+// Author: Vitaly SMETANNIKOV
+
+#ifndef SketcherPrs_Factory_H_
+#define SketcherPrs_Factory_H_
+
+#include "SketcherPrs.h"
+
+#include <GeomAPI_Ax3.h>
+#include <GeomAPI_AISObject.h>
+
+class SketchPlugin_Constraint;
+
+/**
+* Class which creates constraints presentations
+*/
+class SKETCHERPRS_EXPORT SketcherPrs_Factory
+{
+public:
+ /// Creates coincedent constraint presentation
+ /// \param theConstraint the constraint
+ /// \param thePlane the current sketch plane
+ static AISObjectPtr coincidentConstraint(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
+ /// Creates coincedent parallel presentation
+ /// \param theConstraint the constraint
+ /// \param thePlane the current sketch plane
+ static AISObjectPtr parallelConstraint(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Parallel.cpp
+// Created: 16 February 2015
+// Author: Vitaly SMETANNIKOV
+
+#include "SketcherPrs_Parallel.h"
+#include "SketcherPrs_Tools.h"
+
+#include <GeomAPI_Pnt.h>
+
+#include <SketchPlugin_Constraint.h>
+
+#include <AIS_Drawer.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+#include <Prs3d_PointAspect.hxx>
+#include <Prs3d_Root.hxx>
+#include <gp_Pnt2d.hxx>
+#include <Image_AlienPixMap.hxx>
+#include <Graphic3d_MarkerImage.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <Select3D_SensitivePoint.hxx>
+#include <SelectMgr_Selection.hxx>
+#include <Select3D_SensitiveSegment.hxx>
+
+extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
+ const std::string& theAttribute);
+
+#ifdef WIN32
+# define FSEP "\\"
+#else
+# define FSEP "/"
+#endif
+
+
+IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Parallel, AIS_InteractiveObject);
+IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Parallel, AIS_InteractiveObject);
+
+static Handle(Image_AlienPixMap) MyPixMap;
+
+SketcherPrs_Parallel::SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+ : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
+{
+ if (MyPixMap.IsNull()) {
+ TCollection_AsciiString aFile(getenv("NewGeomResources"));
+ aFile += FSEP;
+ aFile += "parallel.png";
+ MyPixMap = new Image_AlienPixMap();
+ if (!MyPixMap->Load(aFile))
+ MyPixMap.Nullify();
+ }
+ if (!MyPixMap.IsNull()) {
+ myAspect = new Graphic3d_AspectMarker3d(MyPixMap);
+ myPntArray = new Graphic3d_ArrayOfPoints(2);
+ myPntArray->AddVertex(0., 0., 0.);
+ myPntArray->AddVertex(0. ,0., 0.);
+ }
+}
+
+void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
+{
+ if (myAspect.IsNull())
+ return;
+
+ std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+ if (aLine1.get() == NULL)
+ return;
+
+ std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+ if (aLine2.get() == NULL)
+ return;
+
+ std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLine1->firstPoint();
+ std::shared_ptr<GeomAPI_Pnt> aPnt2 = aLine1->lastPoint();
+ gp_Pnt aP1((aPnt1->x() + aPnt2->x())/2.,
+ (aPnt1->y() + aPnt2->y())/2.,
+ (aPnt1->z() + aPnt2->z())/2.);
+
+ gp_Vec aVec1(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
+ gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
+ aShift.Normalize();
+ aShift.Multiply(20);
+ aP1.Translate(aShift);
+
+ aPnt1 = aLine2->firstPoint();
+ aPnt2 = aLine2->lastPoint();
+ gp_Pnt aP2((aPnt1->x() + aPnt2->x())/2.,
+ (aPnt1->y() + aPnt2->y())/2.,
+ (aPnt1->z() + aPnt2->z())/2.);
+
+ gp_Vec aVec2(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
+ aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
+ aShift.Normalize();
+ aShift.Multiply(20);
+ aP2.Translate(aShift);
+
+ Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
+ aGroup->SetPrimitivesAspect(myAspect);
+ myPntArray->SetVertice(1, aP1);
+ myPntArray->SetVertice(2, aP2);
+ aGroup->AddPrimitiveArray(myPntArray);
+}
+
+void SketcherPrs_Parallel::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+ const Standard_Integer aMode)
+{
+ std::shared_ptr<GeomAPI_Edge> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+ if (aLine1.get() == NULL)
+ return;
+
+ std::shared_ptr<GeomAPI_Edge> aLine2 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+ if (aLine2.get() == NULL)
+ return;
+
+ Handle(SelectMgr_EntityOwner) eown = new SelectMgr_EntityOwner(this);
+ Handle(Select3D_SensitivePoint) aSP1 = new Select3D_SensitivePoint(eown, myPntArray->Vertice(1));
+ Handle(Select3D_SensitivePoint) aSP2 = new Select3D_SensitivePoint(eown, myPntArray->Vertice(2));
+ aSelection->Add(aSP1);
+ aSelection->Add(aSP2);
+}
+
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Parallel.h
+// Created: 16 February 2015
+// Author: Vitaly SMETANNIKOV
+
+#ifndef SketcherPrs_Parallel_H
+#define SketcherPrs_Parallel_H
+
+#include <GeomAPI_Ax3.h>
+#include <GeomAPI_Edge.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <Graphic3d_ArrayOfPoints.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+#include <Standard_DefineHandle.hxx>
+
+class SketchPlugin_Constraint;
+class SketchPlugin_Sketch;
+
+
+DEFINE_STANDARD_HANDLE(SketcherPrs_Parallel, AIS_InteractiveObject)
+
+/**
+* \ingroup GUI
+* A redefinition of standard AIS Interactive Object in order to provide
+* presentation of coincident constraint
+*/
+class SketcherPrs_Parallel: public AIS_InteractiveObject
+{
+public:
+ /// Constructor
+ /// \param theResult a result object
+ Standard_EXPORT SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
+
+ DEFINE_STANDARD_RTTI(SketcherPrs_Parallel)
+protected:
+ /// Redefinition of virtual function
+ Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
+
+ /// Redefinition of virtual function
+ Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+ const Standard_Integer aMode) ;
+
+private:
+
+ SketchPlugin_Constraint* myConstraint;
+ std::shared_ptr<GeomAPI_Ax3> myPlane;
+ Handle(Graphic3d_AspectMarker3d) myAspect;
+ Handle(Graphic3d_ArrayOfPoints) myPntArray;
+};
+
+#endif
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Tools.cpp
+// Created: 10 March 2015
+// Author: Vitaly SMETANNIKOV
+
+#include "SketcherPrs_Tools.h"
+
+#include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Circle.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeRefAttr.h>
+
+#include <GeomDataAPI_Point2D.h>
+
+
+namespace SketcherPrs_Tools {
+
+
+std::shared_ptr<GeomAPI_Edge> getLine(SketchPlugin_Constraint* theFeature,
+ const std::string& theAttrName)
+{
+ std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(theAttrName));
+
+ ObjectPtr aObject = anAttr->object();
+ ResultConstructionPtr aRes = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObject);
+ if (aRes.get() != NULL) {
+ std::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
+ if (aShape.get() != NULL) {
+ return std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aShape));
+ }
+ }
+ return std::shared_ptr<GeomAPI_Edge>();
+}
+
+
+std::shared_ptr<GeomAPI_Pnt2d> getPoint(SketchPlugin_Constraint* theFeature,
+ const std::string& theAttribute)
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
+
+ if (!theFeature->data())
+ return std::shared_ptr<GeomAPI_Pnt2d>();
+
+ FeaturePtr aFeature;
+ std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(theAttribute));
+ if (anAttr)
+ aFeature = ModelAPI_Feature::feature(anAttr->object());
+
+ if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
+
+ else if (aFeature && aFeature->getKind() == SketchPlugin_Circle::ID())
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
+
+ else if (anAttr->attr()) {
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+ }
+ return aPointAttr->pnt();
+}
+
+
+};
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Tools.h
+// Created: 10 March 2015
+// Author: Vitaly SMETANNIKOV
+
+#ifndef SketcherPrs_Tools_H
+#define SketcherPrs_Tools_H
+
+#include "SketcherPrs.h"
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Pnt2d.h>
+#include <string>
+
+class SketchPlugin_Constraint;
+
+namespace SketcherPrs_Tools {
+
+ std::shared_ptr<GeomAPI_Edge> getLine(SketchPlugin_Constraint* theFeature,
+ const std::string& theAttrName);
+
+ std::shared_ptr<GeomAPI_Pnt2d> getPoint(SketchPlugin_Constraint* theFeature,
+ const std::string& theAttrName);
+
+};
+
+#endif
\ No newline at end of file
XGUI.h
XGUI_ActionsMgr.h
XGUI_ContextMenuMgr.h
+ XGUI_CustomPrs.h
XGUI_DataTreeModel.h
XGUI_Displayer.h
XGUI_DocumentDataModel.h
SET(PROJECT_SOURCES
XGUI_ActionsMgr.cpp
XGUI_ContextMenuMgr.cpp
+ XGUI_CustomPrs.cpp
XGUI_Displayer.cpp
XGUI_DocumentDataModel.cpp
XGUI_ErrorDialog.cpp
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: XGUI_CustomPrs.cpp
+// Created: 10 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#include <XGUI_CustomPrs.h>
+
+#include <ModelAPI_AttributeIntArray.h>
+#include <Config_PropManager.h>
+
+#include <vector>
+
+
+void getColor(ResultPtr theResult, std::vector<int>& theColor)
+{
+ theColor.clear();
+ // get color from the attribute of the result
+ if (theResult.get() != NULL && theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
+ AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+ if (aColorAttr.get() && aColorAttr->size()) {
+ theColor.push_back(aColorAttr->value(0));
+ theColor.push_back(aColorAttr->value(1));
+ theColor.push_back(aColorAttr->value(2));
+ }
+ }
+}
+
+void getDefaultColor(ResultPtr theResult, AISObjectPtr thePrs, std::vector<int>& theColor)
+{
+ theColor.clear();
+ // get default color from the preferences manager for the given result
+ if (theColor.empty()) {
+ std::string aSection, aName, aDefault;
+ theResult->colorConfigInfo(aSection, aName, aDefault);
+ if (!aSection.empty() && !aName.empty()) {
+ theColor = Config_PropManager::color(aSection, aName, aDefault);
+ }
+ }
+ if (theColor.empty()) // all AIS objects, where the color is not set, a white.
+ // The color should be defined in XML or set in the attribute
+ theColor = Config_PropManager::color("Visualization", "object_default_color", "#ffffff");
+}
+
+bool XGUI_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
+{
+ std::vector<int> aColor;
+
+ getColor(theResult, aColor);
+ if (aColor.empty())
+ getDefaultColor(theResult, thePrs, aColor);
+
+ return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: XGUI_CustomPrs.hxx
+// Created: 10 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef XGUI_CustomPrs_H
+#define XGUI_CustomPrs_H
+
+#include "XGUI.h"
+#include <GeomAPI_ICustomPrs.h>
+#include <GeomAPI_AISObject.h>
+#include <ModelAPI_Result.h>
+
+/**
+* Interface of a class which can provide specific customization of
+* object presentation
+*/
+class XGUI_CustomPrs : public GeomAPI_ICustomPrs
+{
+public:
+ XGUI_EXPORT virtual ~XGUI_CustomPrs() {};
+
+ /// Modifies the given presentation in the custom way.
+ virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs);
+};
+
+#endif
#include "XGUI_ViewerProxy.h"
#include "XGUI_SelectionMgr.h"
#include "XGUI_Selection.h"
+#include "XGUI_CustomPrs.h"
#include <AppElements_Viewer.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Tools.h>
-#include <ModelAPI_AttributeColor.h>
+#include <ModelAPI_AttributeIntArray.h>
#include <ModuleBase_ResultPrs.h>
: myWorkshop(theWorkshop)
{
enableUpdateViewer(true);
+ myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new XGUI_CustomPrs());
}
XGUI_Displayer::~XGUI_Displayer()
aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
- customizeObject(theObject);
+ bool isCustomized = customizeObject(theObject);
+ if (isCustomized)
+ aContext->Redisplay(anAISIO, false);
+
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.
+ bool isEqualShapes = false;
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (aResult.get() != NULL) {
Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
std::shared_ptr<GeomAPI_Shape> anAISShapePtr(new GeomAPI_Shape());
anAISShapePtr->setImpl(new TopoDS_Shape(aShape));
- if (aShapePtr->isEqual(anAISShapePtr))
- return;
+ isEqualShapes = aShapePtr->isEqual(anAISShapePtr);
}
}
}
// Customization of presentation
- customizeObject(theObject);
-
- aContext->Redisplay(aAISIO, false);
- if (isUpdateViewer)
- updateViewer();
+ bool isCustomized = customizeObject(theObject);
+ if (!isEqualShapes || isCustomized) {
+ aContext->Redisplay(aAISIO, false);
+ if (isUpdateViewer)
+ updateViewer();
+ }
}
}
}
}
-void XGUI_Displayer::customizeObject(ObjectPtr theObject)
+bool 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);
+ // Customization of presentation
+ GeomCustomPrsPtr aCustomPrs;
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+ if (aFeature.get() != NULL) {
+ GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
+ if (aCustPrs.get() != NULL)
+ aCustomPrs = aCustPrs;
}
- 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);
- }
+ if (aCustomPrs.get() == NULL) {
+ // we ignore presentable not customized objects
+ GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
+ if (aPrs.get() != NULL)
+ return false;
+ aCustomPrs = myCustomPrs;
}
+ return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs);
}
#include <ModuleBase_Definitions.h>
#include <ModuleBase_ViewerPrs.h>
+#include <GeomAPI_ICustomPrs.h>
+
#include <SelectMgr_AndFilter.hxx>
#include <QString>
* 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
+ * \return the true state if there is changes and the presentation is customized
*/
- void customizeObject(ObjectPtr theObject);
+ bool customizeObject(ObjectPtr theObject);
protected:
/// Reference to workshop
/// A container for selection filters
Handle(SelectMgr_AndFilter) myAndFilter;
+ /// A default custom presentation, which is used if the displayed feature is not a custom presentation
+ GeomCustomPrsPtr myCustomPrs;
+
/// Definition of a type of map which defines correspondance between objects and presentations
typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
#include <ModelAPI_ResultGroup.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_AttributeIntArray.h>
//#include <PartSetPlugin_Part.h>
#include <QMenu>
#include <QToolButton>
#include <QAction>
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QHBoxLayout>
+#include <QtxColorButton.h>
#ifdef _DEBUG
#include <QDebug>
return;
}
- SessionPtr aMgr = ModelAPI_Session::get();
QString aDescription = tr("Delete %1");
QStringList aObjectNames;
foreach (ObjectPtr aObj, theList) {
aObjectNames << QString::fromStdString(aObj->data()->name());
}
aDescription = aDescription.arg(aObjectNames.join(", "));
+ SessionPtr aMgr = ModelAPI_Session::get();
aMgr->startOperation(aDescription.toStdString());
std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
aLast = aRefFeatures.end();
}
//**************************************************************
-#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);
- }
+ std::vector<int> aColor;
+ foreach(ObjectPtr anObject, theObjects) {
+
+ AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
+ aColor.resize(3);
+ anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
+ if (!aColor.empty())
+ break;
}
- // there is no object with the color attribute
- if (aColorAttr.get() == NULL)
+ if (aColor.size() != 3)
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);
+ QDialog* aDlg = new QDialog();
+ QVBoxLayout* aLay = new QVBoxLayout(aDlg);
+
+ QtxColorButton* aColorBtn = new QtxColorButton(aDlg);
+ aColorBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
- QtxColorButton* aColorBtn = new QtxColorButton(&aDlg);
aLay->addWidget(aColorBtn);
- aColorBtn->setColor(QColor(aRed, aGreen, aBlue));
+ aColorBtn->setColor(QColor(aColor[0], aColor[1], aColor[2]));
- QPoint aPoint = QCursor::pos();
- aDlg.move(aPoint);
+ QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+ Qt::Horizontal, aDlg);
+ connect(aButtons, SIGNAL(accepted()), aDlg, SLOT(accept()));
+ connect(aButtons, SIGNAL(rejected()), aDlg, SLOT(reject()));
+ aLay->addWidget(aButtons);
- bool isDone = aDlg.exec() == QDialog::Accepted;
+ aDlg->move(QCursor::pos());
+ bool isDone = aDlg->exec() == QDialog::Accepted;
if (!isDone)
return;
aGreenResult = aColorResult.green(),
aBlueResult = aColorResult.blue();
- if (aRedResult == aRed && aGreenResult == aGreen && aBlueResult == aBlue)
+ if (aRedResult == aColor[0] && aGreenResult == aColor[1] && aBlueResult == aColor[2])
return;
// 3. abort the previous operation and start a new one
- if(!isActiveOperationAborted())
- return;
+ SessionPtr aMgr = ModelAPI_Session::get();
+ bool aWasOperation = aMgr->isOperation(); // keep this value
+ if (!aWasOperation) {
+ QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
+ aMgr->startOperation(aDescription.toStdString());
+ }
// 4. set the value to all results
+ static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ AttributeIntArrayPtr 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);
- if (aColorAttr.get() != NULL)
- aColorAttr->setValues(aRedResult, aGreenResult, aBlueResult);
+ aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+ if (aColorAttr.get() != NULL) {
+ if (!aColorAttr->size()) {
+ aColorAttr->setSize(3);
+ }
+ aColorAttr->setValue(0, aRedResult);
+ aColorAttr->setValue(1, aGreenResult);
+ aColorAttr->setValue(2, aBlueResult);
+ ModelAPI_EventCreator::get()->sendUpdated(anObj, EVENT_DISP);
}
}
}
+ if (!aWasOperation)
+ aMgr->finishOperation();
+ updateCommandStatus();
}
//**************************************************************