<plugin library="FeaturesPlugin" configuration="plugin-Features.xml"/>
<plugin library="ExchangePlugin" configuration="plugin-Exchange.xml"/>
<plugin script="ConnectorPlugin" configuration="plugin-Connector.xml" dependency="Geometry"/>
+ <plugin library="ParametersPlugin" configuration="plugin-Parameters.xml"/>
<plugin library="SketchSolver"/>
<plugin library="GeomValidators"/>
<plugin library="DFBrowser" internal="true"/>
icon=":icons/point.png"
tooltip="Select a first point"
shape_types="vertex">
- <validator id="ModuleBase_ValidatorNoConstructionSubShapes"/>
+ <validator id="GeomValidators_ConstructionComposite"/>
</shape_selector>
<shape_selector id="SecondPoint"
label="Second point"
icon=":icons/point.png"
tooltip="Select a second point"
shape_types="vertex">
- <validator id="ModuleBase_ValidatorNoConstructionSubShapes"/>
+ <validator id="GeomValidators_ConstructionComposite"/>
<validator id="PartSet_DifferentShapes"/>
</shape_selector>
</box>
label="Plane face"
tooltip="Select a planar face"
shape_types="face">
- <validator id="ModuleBase_ValidatorFace" parameters="plane"/>
+ <validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
<doublevalue id="distance"
label="Distance"
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <GeomAPI_Edge.h>
#include <GeomAPI_Face.h>
#include <GeomAPI_Pln.h>
#include <GeomAlgoAPI_Placement.h>
void FeaturesPlugin_Placement::initAttributes()
{
- data()->addAttribute(FeaturesPlugin_Placement::BASE_FACE_ID(), ModelAPI_AttributeSelection::type());
- data()->addAttribute(FeaturesPlugin_Placement::ATTRACT_FACE_ID(), ModelAPI_AttributeSelection::type());
+ data()->addAttribute(FeaturesPlugin_Placement::BASE_OBJECT_ID(), ModelAPI_AttributeSelection::type());
+ data()->addAttribute(FeaturesPlugin_Placement::ATTRACT_OBJECT_ID(), ModelAPI_AttributeSelection::type());
+ data()->addAttribute(FeaturesPlugin_Placement::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
+ data()->addAttribute(FeaturesPlugin_Placement::CENTERING_ID(), ModelAPI_AttributeBoolean::type());
}
void FeaturesPlugin_Placement::execute()
{
// Verify the base face
- std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = std::dynamic_pointer_cast<
- ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Placement::BASE_FACE_ID()));
- if (!aFaceRef)
+ std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = std::dynamic_pointer_cast<
+ ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Placement::BASE_OBJECT_ID()));
+ if (!anObjRef)
return;
- std::shared_ptr<GeomAPI_Shape> aBaseFace =
- std::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
- if (!aBaseFace)
+ std::shared_ptr<GeomAPI_Shape> aBaseShape =
+ std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+ if (!aBaseShape)
return;
- std::shared_ptr<GeomAPI_Shape> aBaseFaceContext;
- ResultPtr aContextRes = aFaceRef->context();
+ std::shared_ptr<GeomAPI_Shape> aBaseObject;
+ ResultPtr aContextRes = anObjRef->context();
if (aContextRes) {
if (aContextRes->groupName() == ModelAPI_ResultBody::group())
- aBaseFaceContext = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
+ aBaseObject = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group())
- aBaseFaceContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
+ aBaseObject = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
}
- if (!aBaseFaceContext) {
+ if (!aBaseObject) {
static const std::string aContextError = "The selection context is bad";
setError(aContextError);
return;
}
// Verify the attractive face
- aFaceRef = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(
- data()->attribute(FeaturesPlugin_Placement::ATTRACT_FACE_ID()));
+ anObjRef = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(
+ data()->attribute(FeaturesPlugin_Placement::ATTRACT_OBJECT_ID()));
- std::shared_ptr<GeomAPI_Shape> aSlaveObjectFace =
- std::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
- if (!aSlaveObjectFace)
+ std::shared_ptr<GeomAPI_Shape> aSlaveShape =
+ std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+ if (!aSlaveShape)
return;
std::shared_ptr<GeomAPI_Shape> aSlaveObject;
- aContextRes = aFaceRef->context();
+ aContextRes = anObjRef->context();
if (aContextRes) {
if (aContextRes->groupName() == ModelAPI_ResultBody::group())
aSlaveObject = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
return;
}
- // Verify faces planarity
- std::shared_ptr<GeomAPI_Face> aBaseFace1(new GeomAPI_Face(aBaseFace));
- std::shared_ptr<GeomAPI_Face> aSlaveFace1(new GeomAPI_Face(aSlaveObjectFace));
- if (!aBaseFace1->isPlanar() || !aSlaveFace1->isPlanar()) {
- static const std::string aPlanarityError = "One of selected face is not planar";
- setError(aPlanarityError);
- return;
+ // Verify planarity of faces and linearity of edges
+ std::shared_ptr<GeomAPI_Shape> aShapes[2] = {aBaseShape, aSlaveShape};
+ for (int i = 0; i < 2; i++) {
+ if (aShapes[i]->isFace()) {
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aShapes[i]));
+ if (!aFace->isPlanar()) {
+ static const std::string aPlanarityError = "One of selected faces is not planar";
+ setError(aPlanarityError);
+ return;
+ }
+ }
+ else if (aShapes[i]->isEdge()) {
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShapes[i]));
+ if (!anEdge->isLine()) {
+ static const std::string aLinearityError = "One of selected endges is not linear";
+ setError(aLinearityError);
+ return;
+ }
+ }
}
- std::shared_ptr<GeomAPI_Pln> aBasePlane = aBaseFace1->getPlane();
- std::shared_ptr<GeomAPI_Pln> aSlavePlane = aSlaveFace1->getPlane();
+ // Flags of the Placement
+ AttributeBooleanPtr aBoolAttr = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
+ data()->attribute(FeaturesPlugin_Placement::REVERSE_ID()));
+ bool isReverse = aBoolAttr->value();
+ aBoolAttr = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
+ data()->attribute(FeaturesPlugin_Placement::CENTERING_ID()));
+ bool isCentering = aBoolAttr->value();
std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
- GeomAlgoAPI_Placement aFeature(aSlaveObject, aSlavePlane, aBasePlane);
+ GeomAlgoAPI_Placement aFeature(aSlaveObject, aBaseObject, aSlaveShape, aBaseShape, isReverse, isCentering);
if(!aFeature.isDone()) {
static const std::string aFeatureError = "Placement algorithm failed";
setError(aFeatureError);
* \ingroup Plugins
* \brief Feature for applying of placement operation: relative movement of Solid.
*
- * Locates the selected attractable_face of the solid in the middle of the selected
- * placement_base face. Faces must be planar. Orientation of the placed solid is
- * depended on the underlied planes of both faces.
+ * Locates the selected placement_attractable_object (face, edge, vertex) of the solid into
+ * the selected placement_base_object. Faces must be planar, edges must be linear.
+ * Orientation of the placed solid depends on the underlied planes of both faces.
*/
class FeaturesPlugin_Placement : public ModelAPI_Feature
{
static const std::string MY_PLACEMENT_ID("Placement");
return MY_PLACEMENT_ID;
}
- /// attribute name of referenced face
- inline static const std::string& BASE_FACE_ID()
+ /// attribute name of referenced object
+ inline static const std::string& BASE_OBJECT_ID()
{
- static const std::string MY_BASE_FACE_ID("placement_base_face");
- return MY_BASE_FACE_ID;
+ static const std::string MY_BASE_OBJECT_ID("placement_base_object");
+ return MY_BASE_OBJECT_ID;
}
/// attribute name of attractable face
- inline static const std::string& ATTRACT_FACE_ID()
+ inline static const std::string& ATTRACT_OBJECT_ID()
{
- static const std::string MY_ATTRACT_FACE_ID("placement_attractable_face");
- return MY_ATTRACT_FACE_ID;
+ static const std::string MY_ATTRACT_OBJECT_ID("placement_attractable_object");
+ return MY_ATTRACT_OBJECT_ID;
+ }
+ /// attribute name of flag of reverse direction
+ inline static const std::string& REVERSE_ID()
+ {
+ static const std::string MY_REVERSE_ID("placement_reverse_direction");
+ return MY_REVERSE_ID;
+ }
+ /// attribute name of flag of centering position
+ inline static const std::string& CENTERING_ID()
+ {
+ static const std::string MY_CENTERING_ID("placement_centering");
+ return MY_CENTERING_ID;
}
/// Returns the kind of a feature
icon=":icons/sketch.png"
tooltip="Select a sketch face"
type_choice="Faces">
- <validator id="PartSet_SketchEntityValidator"/>
+ <validator id="PartSet_SketchEntityValidator" parameters="Sketch"/>
</multi_selector>
<doublevalue
id="size"
<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
<source>
- <shape_selector id="placement_base_face"
- label="Select a face"
+ <shape_selector id="placement_base_object"
+ label="Select an object"
icon=":icons/cut_shape.png"
- tooltip="Select a destination face"
- shape_types="face"
+ tooltip="Select a destination element"
+ shape_types="face edge vertex"
/>
- <shape_selector id="placement_attractable_face"
- label="Select a face"
- icon=":icons/cut_shape.png"
- tooltip="Select a face of moved object"
- shape_types="face"
- concealment="true" >
- <validator id="PartSet_DifferentObjects"/>
+ <shape_selector id="placement_attractable_object"
+ label="Select an object"
+ icon=":icons/cut_shape.png"
+ tooltip="Select an element of moved object"
+ shape_types="face edge vertex"
+ concealment="true" >
+ <validator id="PartSet_DifferentObjects"/>
</shape_selector>
+ <boolvalue id="placement_reverse_direction"
+ label="Reverse"
+ default="false"
+ tooltip="Reverse placement direction"/>
+ <boolvalue id="placement_centering"
+ label="Centering"
+ default="false"
+ tooltip="Center faces under placement"/>
</source>
return;
Quantity_Color aColor = anAIS->Color();
- theR = aColor.Red()*255.;
- theG = aColor.Green()*255.;
- theB = aColor.Blue()*255.;
+ theR = (int)(aColor.Red()*255.);
+ theG = (int)(aColor.Green()*255.);
+ theB = (int)(aColor.Blue()*255.);
}
bool GeomAPI_AISObject::empty() const
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)
/// \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
#include<GeomAPI_Pnt.h>
#include<GeomAPI_Circ.h>
#include<GeomAPI_Dir.h>
+#include<GeomAPI_Lin.h>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Edge.hxx>
return std::shared_ptr<GeomAPI_Circ>(); // not circle
}
+std::shared_ptr<GeomAPI_Lin> GeomAPI_Edge::line()
+{
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+ double aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
+ if (aCurve) {
+ Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCurve);
+ if (aLine) {
+ gp_Pnt aStartPnt = aLine->Value(aFirst);
+ std::shared_ptr<GeomAPI_Pnt> aStart(
+ new GeomAPI_Pnt(aStartPnt.X(), aStartPnt.Y(), aStartPnt.Z()));
+ gp_Pnt aEndPnt = aLine->Value(aLast);
+ std::shared_ptr<GeomAPI_Pnt> aEnd(
+ new GeomAPI_Pnt(aEndPnt.X(), aEndPnt.Y(), aEndPnt.Z()));
+ return std::shared_ptr<GeomAPI_Lin>(new GeomAPI_Lin(aStart, aEnd));
+ }
+ }
+ return std::shared_ptr<GeomAPI_Lin>(); // not circle
+}
+
bool GeomAPI_Edge::isEqual(const std::shared_ptr<GeomAPI_Shape> theEdge) const
{
class GeomAPI_Pnt;
class GeomAPI_Circ;
+class GeomAPI_Lin;
/**\class GeomAPI_Edge
* \ingroup DataModel
/// Returns the Last vertex coordinates of the edge
std::shared_ptr<GeomAPI_Pnt> lastPoint();
- /// Returns a circle if edge is based on the cirsle curve
+ /// Returns a circle if edge is based on the circle curve
std::shared_ptr<GeomAPI_Circ> circle();
+ /// Returns a line if edge is based on the linear curve
+ std::shared_ptr<GeomAPI_Lin> line();
+
/// Returns true if the current edge is geometrically equal to the given edge
bool isEqual(const std::shared_ptr<GeomAPI_Shape> theEdge) const;
};
#include <GeomAPI_Lin.h>
#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Dir.h>
#include <gp_Dir.hxx>
#include <gp_Lin.hxx>
{
}
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Lin::location()
+{
+ gp_Pnt aLoc = impl<gp_Lin>().Location();
+ return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
+}
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_Lin::direction()
+{
+ const gp_Dir& aDir = impl<gp_Lin>().Direction();
+ return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
+}
+
double GeomAPI_Lin::distance(const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
{
return MY_LIN->Distance(thePoint->impl<gp_Pnt>());
#include <GeomAPI_Interface.h>
#include <memory>
+class GeomAPI_Dir;
class GeomAPI_Pnt;
/**\class GeomAPI_Lin
GeomAPI_Lin(const std::shared_ptr<GeomAPI_Pnt>& theStart,
const std::shared_ptr<GeomAPI_Pnt>& theEnd);
+ /// Returns point on the line (first point)
+ std::shared_ptr<GeomAPI_Pnt> location();
+
+ /// Returns a line direction
+ std::shared_ptr<GeomAPI_Dir> direction();
+
/// Distance between two points
double distance(const std::shared_ptr<GeomAPI_Pnt>& thePoint) const;
/// Intersection of two lines
#include <GeomAPI_Lin2d.h>
#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Dir2d.h>
#include <gp_Dir2d.hxx>
#include <gp_Lin2d.hxx>
{
}
+std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Lin2d::location()
+{
+ gp_Pnt2d aLoc = impl<gp_Lin2d>().Location();
+ return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aLoc.X(), aLoc.Y()));
+}
+
+std::shared_ptr<GeomAPI_Dir2d> GeomAPI_Lin2d::direction()
+{
+ const gp_Dir2d& aDir = impl<gp_Lin2d>().Direction();
+ return std::shared_ptr<GeomAPI_Dir2d>(new GeomAPI_Dir2d(aDir.X(), aDir.Y()));
+}
+
double GeomAPI_Lin2d::distance(const std::shared_ptr<GeomAPI_Pnt2d>& theOther) const
{
return MY_LIN2D->Distance(theOther->impl<gp_Pnt2d>());
#include <GeomAPI_Interface.h>
#include <memory>
+class GeomAPI_Dir2d;
class GeomAPI_Pnt2d;
/**\class GeomAPI_Lin2d
GeomAPI_Lin2d(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
const std::shared_ptr<GeomAPI_Pnt2d>& theEnd);
+ /// Returns point on the line (first point)
+ std::shared_ptr<GeomAPI_Pnt2d> location();
+
+ /// Returns a line direction
+ std::shared_ptr<GeomAPI_Dir2d> direction();
+
/// Distance between two points
double distance(const std::shared_ptr<GeomAPI_Pnt2d>& theOther) const;
/// Intersection of two lines
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));
+ myPlane = std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(theOrigin, theDirX, theNorm));
}
\ No newline at end of file
/// \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:
#include <GeomAlgoAPI_Placement.h>
#include <GeomAlgoAPI_DFLoader.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Pln.h>
+#include <GeomAPI_Vertex.h>
+#include <GeomAPI_XYZ.h>
#include <BRepBuilderAPI_Transform.hxx>
#include <gp_Trsf.hxx>
#include <gp_Quaternion.hxx>
#include <TopExp_Explorer.hxx>
#include <BRepCheck_Analyzer.hxx>
+#include <BRepClass3d_SolidClassifier.hxx>
#include <GProp_GProps.hxx>
#include <BRepGProp.hxx>
#include <Precision.hxx>
+
#define DEB_PLACEMENT 1
GeomAlgoAPI_Placement::GeomAlgoAPI_Placement(
- std::shared_ptr<GeomAPI_Shape> theAttractiveFace,
- std::shared_ptr<GeomAPI_Pln> theSourcePlane,
- std::shared_ptr<GeomAPI_Pln> theDestPlane)
+ std::shared_ptr<GeomAPI_Shape> theSourceSolid,
+ std::shared_ptr<GeomAPI_Shape> theDestSolid,
+ std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Shape> theDestShape,
+ bool theIsReverse,
+ bool theIsCentering)
: myDone(false),
myShape(new GeomAPI_Shape())
{
- build(theAttractiveFace, theSourcePlane, theDestPlane);
+ build(theSourceSolid, theDestSolid, theSourceShape, theDestShape, theIsReverse, theIsCentering);
}
void GeomAlgoAPI_Placement::build(
- const std::shared_ptr<GeomAPI_Shape>& theAttractiveShape,
- const std::shared_ptr<GeomAPI_Pln>& theSourcePlane,
- const std::shared_ptr<GeomAPI_Pln>& theDestPlane)
+ const std::shared_ptr<GeomAPI_Shape>& theSourceSolid,
+ const std::shared_ptr<GeomAPI_Shape>& theDestSolid,
+ const std::shared_ptr<GeomAPI_Shape>& theSourceShape,
+ const std::shared_ptr<GeomAPI_Shape>& theDestShape,
+ bool theIsReverse,
+ bool theIsCentering)
{
- std::shared_ptr<GeomAPI_Dir> aSourceDir = theSourcePlane->direction();
- std::shared_ptr<GeomAPI_Pnt> aSourceLoc = theSourcePlane->location();
- std::shared_ptr<GeomAPI_Dir> aDestDir = theDestPlane->direction();
- std::shared_ptr<GeomAPI_Pnt> aDestLoc = theDestPlane->location();
+ // Filling the parameters of the objects
+ static const int aNbObjects = 2;
+ gp_Pnt aSrcDstPoints[aNbObjects]; // points on the selected objects (0 - source, 1 - destination)
+ gp_Vec aSrcDstNormals[aNbObjects]; // normal vectors, if planar faces are selected
+ gp_Vec aSrcDstDirections[aNbObjects]; // directions of linear edges
+ bool hasNormal[aNbObjects];
+ bool hasDirection[aNbObjects];
+ std::shared_ptr<GeomAPI_Shape> aShapes[aNbObjects] = {theSourceShape, theDestShape};
+
+ for (int i = 0; i < aNbObjects; i++) {
+ if (aShapes[i]->isFace()) {
+ std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aShapes[i]));
+ std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
+ std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+ std::shared_ptr<GeomAPI_Pnt> aLoc = aPlane->location();
+ aSrcDstPoints[i].SetCoord(aLoc->x(), aLoc->y(), aLoc->z());
+ aSrcDstNormals[i].SetCoord(aDir->x(), aDir->y(), aDir->z());
+ } else if (aShapes[i]->isEdge()) {
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShapes[i]));
+ std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
+ std::shared_ptr<GeomAPI_Dir> aDir = aLine->direction();
+ std::shared_ptr<GeomAPI_Pnt> aFirstPnt = anEdge->firstPoint();
+ std::shared_ptr<GeomAPI_Pnt> aLastPnt = anEdge->lastPoint();
+ std::shared_ptr<GeomAPI_XYZ> aLoc = aFirstPnt->xyz()->added(aLastPnt->xyz())->multiplied(0.5);
+ aSrcDstPoints[i].SetCoord(aLoc->x(), aLoc->y(), aLoc->z());
+ aSrcDstDirections[i].SetCoord(aDir->x(), aDir->y(), aDir->z());
+ } else if (aShapes[i]->isVertex()) {
+ std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aShapes[i]));
+ std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+ aSrcDstPoints[i].SetCoord(aPnt->x(), aPnt->y(), aPnt->z());
+ } else // something goes wrong
+ return;
+ hasNormal[i] = aSrcDstNormals[i].SquareMagnitude() >= Precision::SquareConfusion();
+ hasDirection[i] = aSrcDstDirections[i].SquareMagnitude() >= Precision::SquareConfusion();
+ }
+
+ // Initial shapes
+ const TopoDS_Shape& aSourceShape = theSourceSolid->impl<TopoDS_Shape>();
+ const TopoDS_Shape& aDestShape = theDestSolid->impl<TopoDS_Shape>();
+ // Check the material of the solids to be on the correct side
+ BRepClass3d_SolidClassifier aClassifier;
+ static const double aTransStep = 10. * Precision::Confusion();
+ if (hasNormal[0]) {
+ aClassifier.Load(aSourceShape);
+ gp_Pnt aPoint = aSrcDstPoints[0];
+ aPoint.Translate(aSrcDstNormals[0] * aTransStep);
+ aClassifier.Perform(aPoint, Precision::Confusion());
+ if ((aClassifier.State() == TopAbs_OUT && !theIsReverse) ||
+ (aClassifier.State() == TopAbs_IN && theIsReverse))
+ aSrcDstNormals[0].Reverse();
+ }
+ if (hasNormal[1]) {
+ aClassifier.Load(aDestShape);
+ gp_Pnt aPoint = aSrcDstPoints[1];
+ aPoint.Translate(aSrcDstNormals[1] * aTransStep);
+ aClassifier.Perform(aPoint, Precision::Confusion());
+ if (aClassifier.State() == TopAbs_IN)
+ aSrcDstNormals[1].Reverse();
+ }
+
+ // Calculate directions, which comply the normal, for vertices and edges
+ if (!hasNormal[0] || !hasNormal[1]) {
+ if (hasNormal[0] || hasNormal[1]) { // plane with line or vertex
+ if (hasDirection[0] || hasDirection[1]) { // plane - line
+ int anInd = hasDirection[0] ? 0 : 1;
+ gp_Vec aVec = aSrcDstNormals[1 - anInd].Crossed(aSrcDstDirections[anInd]);
+ if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // normal and direction are collinear
+ aVec = aSrcDstNormals[1 - anInd].Crossed(
+ gp_Vec(aSrcDstPoints[1 - anInd], aSrcDstPoints[anInd]));
+ if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // normal and points direction are collinear
+ if (Abs(aSrcDstNormals[1 - anInd].Y()) >= Precision::Confusion() ||
+ Abs(aSrcDstNormals[1 - anInd].Z()) >= Precision::Confusion())
+ aVec = gp::DX();
+ else
+ aVec = gp::DY();
+ }
+ }
+ aSrcDstNormals[anInd] = aSrcDstDirections[anInd].Crossed(aVec).Normalized();
+ } else { // plane - point
+ int anInd = hasNormal[0] ? 1 : 0;
+ aSrcDstNormals[anInd] = aSrcDstNormals[1 - anInd];
+ }
+ } else {
+ if (hasDirection[0] && hasDirection[1]) { // line - line
+ gp_Vec aVec = aSrcDstDirections[0].Crossed(aSrcDstDirections[1]);
+ if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // lines are parallel
+ aVec = aSrcDstDirections[0].Crossed(gp_Vec(aSrcDstPoints[0], aSrcDstPoints[1]));
+ if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // lines are equal
+ if (Abs(aSrcDstDirections[0].Y()) >= Precision::Confusion() ||
+ Abs(aSrcDstDirections[0].Z()) >= Precision::Confusion())
+ aVec = gp::DX();
+ else
+ aVec = gp::DY();
+ }
+ }
+ aSrcDstNormals[0] = aSrcDstDirections[0].Crossed(aVec);
+ aSrcDstNormals[0].Normalize();
+ aSrcDstNormals[1] = aSrcDstDirections[1].Crossed(aVec);
+ aSrcDstNormals[1].Normalize();
+ if (aSrcDstDirections[0].Dot(aSrcDstDirections[1]) < -Precision::Confusion())
+ aSrcDstNormals[1].Reverse();
+ } else if (!hasDirection[0] && !hasDirection[1]) { // point - point
+ aSrcDstNormals[0] = gp_Vec(aSrcDstPoints[0], aSrcDstPoints[1]);
+ aSrcDstNormals[0].Normalize();
+ aSrcDstNormals[1] = -aSrcDstNormals[0];
+ } else { // line - point
+ int anInd = hasDirection[0] ? 0 : 1;
+ gp_Vec aVec(aSrcDstPoints[anInd], aSrcDstPoints[1 - anInd]);
+ aVec.Cross(aSrcDstDirections[anInd]);
+ if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // point is on line
+ if (Abs(aSrcDstDirections[1 - anInd].Y()) >= Precision::Confusion() ||
+ Abs(aSrcDstDirections[1 - anInd].Z()) >= Precision::Confusion())
+ aVec = gp::DX();
+ else
+ aVec = gp::DY();
+ }
+ aSrcDstNormals[anInd] = aSrcDstDirections[anInd].Crossed(aVec).Normalized();
+ aSrcDstNormals[1 - anInd] = aSrcDstNormals[anInd];
+ }
+ }
+ }
+
+ // Reverse the normal if it was not done before
+ if (!hasNormal[0] && theIsReverse)
+ aSrcDstNormals[0].Reverse();
// Calculate transformation
gp_Trsf aTrsf;
- gp_Vec aSrcDir(aSourceDir->x(), aSourceDir->y(), aSourceDir->z());
- gp_Vec aDstDir(aDestDir->x(), aDestDir->y(), aDestDir->z());
+ gp_Vec aSrcDir = aSrcDstNormals[0];
+ gp_Vec aDstDir = aSrcDstNormals[1];
+ gp_Vec aSrcDir = aSrcDstNormals[0];
+ gp_Vec aDstDir = aSrcDstNormals[1];
+ // Calculate rotation
gp_Quaternion aRot(aSrcDir, aDstDir);
aTrsf.SetRotation(aRot);
- gp_Vec aSrcCenter(aSourceLoc->x(), aSourceLoc->y(), aSourceLoc->z());
- aSrcCenter.Transform(aTrsf);
- gp_Vec aTrans(aDestLoc->x() - aSrcCenter.X(),
- aDestLoc->y() - aSrcCenter.Y(),
- aDestLoc->z() - aSrcCenter.Z());
+ // Calculate translation
+ gp_Vec aSrcLoc(aSrcDstPoints[0].XYZ());
+ gp_Vec aDstLoc(aSrcDstPoints[1].XYZ());
+ if (!theIsCentering)
+ aDstLoc = aSrcLoc + gp_Vec(aDstDir) * (aDstLoc-aSrcLoc).Dot(aDstDir);
+ aSrcLoc.Transform(aTrsf);
+ gp_Vec aTrans = aDstLoc - aSrcLoc;
aTrsf.SetTransformation(aRot, aTrans);
// Transform the shape with copying it
- const TopoDS_Shape& aShape = theAttractiveShape->impl<TopoDS_Shape>();
- BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aShape, aTrsf, true);
+ BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
if(aBuilder) {
setImpl(aBuilder);
myDone = aBuilder->IsDone() == Standard_True;
#include <GeomAlgoAPI.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_Dir.h>
-#include <GeomAPI_Pln.h>
+#include <GeomAPI_Face.h>
#include <GeomAlgoAPI_MakeShape.h>
#include <GeomAPI_DataMapOfShapeShape.h>
#include <memory>
/**\class GeomAlgoAPI_Placement
* \ingroup DataAlgo
- * \brief Creates the copied object which face is placed on the given plane
+ * \brief Creates the copied object which sub-element is placed on the given element
*/
class GeomAlgoAPI_Placement : public GeomAPI_Interface
{
public:
/** \brief Creates an object which is obtained from current object by transformation calculated
- * as a movement of the source plane to be coincident with the destination plane
- * \param[in] theAttractiveShape shape to be moved
- * \param[in] theSourcePlane plane on the shape to be made coincident with destination plane
- * \param[in] theDestPlane destination plane
+ * as a movement of the source object to be coincident with the destination object
+ * \param[in] theSourceSolid a shape to be moved
+ * \param[in] theDestSolid invariant shape
+ * \param[in] theSourceShape a shape on the solid to be made coincident with destination object
+ * \param[in] theDestShape destination object
+ * \param[in] theIsReverse indicates that the solid materials should be on the same side against the destination plane
+ * \param[in] theIsCentering indicates the planes should be centered
*/
- GEOMALGOAPI_EXPORT GeomAlgoAPI_Placement(std::shared_ptr<GeomAPI_Shape> theAttractiveShape,
- std::shared_ptr<GeomAPI_Pln> theSourcePlane,
- std::shared_ptr<GeomAPI_Pln> theDestPlane);
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_Placement(std::shared_ptr<GeomAPI_Shape> theSourceSolid,
+ std::shared_ptr<GeomAPI_Shape> theDestSolid,
+ std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Shape> theDestShape,
+ bool theIsReverse = false,
+ bool theIsCentering = false);
/// Returns True if algorithm succeed
GEOMALGOAPI_EXPORT const bool isDone() const
private:
/// builds resulting shape
- void build(const std::shared_ptr<GeomAPI_Shape>& theAttractiveShape,
- const std::shared_ptr<GeomAPI_Pln>& theSourcePlane,
- const std::shared_ptr<GeomAPI_Pln>& theDestPlane);
+ void build(const std::shared_ptr<GeomAPI_Shape>& theSourceSolid,
+ const std::shared_ptr<GeomAPI_Shape>& theDestSolid,
+ const std::shared_ptr<GeomAPI_Shape>& theSourceShape,
+ const std::shared_ptr<GeomAPI_Shape>& theDestShape,
+ bool theIsReverse,
+ bool theIsCentering);
/// fields
bool myDone;
// Author: Mikhail PONIKAROV
#include "GeomData_Dir.h"
-#include "GeomAPI_Dir.h"
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_XYZ.h>
#include <gp_Dir.hxx>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Data.h>
new GeomAPI_Dir(myCoords->Value(0), myCoords->Value(1), myCoords->Value(2)));
}
+std::shared_ptr<GeomAPI_XYZ> GeomData_Dir::xyz()
+{
+ return std::shared_ptr<GeomAPI_XYZ>(
+ new GeomAPI_XYZ(myCoords->Value(0), myCoords->Value(1), myCoords->Value(2)));
+}
+
GeomData_Dir::GeomData_Dir(TDF_Label& theLabel)
{
myIsInitialized = theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True;
#include <memory>
class GeomAPI_Dir;
+class GeomAPI_XYZ;
/**\class GeomData_Dir
* \ingroup DataModel
GEOMDATA_EXPORT virtual double z() const;
/// Returns the direction of this attribute
GEOMDATA_EXPORT virtual std::shared_ptr<GeomAPI_Dir> dir();
+ /// Returns the coordinates of this attribute
+ GEOMDATA_EXPORT virtual std::shared_ptr<GeomAPI_XYZ> xyz();
protected:
/// Initializes attributes
#include <ModelAPI_Attribute.h>
class GeomAPI_Dir;
+class GeomAPI_XYZ;
/**\class GeomDataAPI_Dir
* \ingroup DataModel
virtual double z() const = 0;
/// Returns the direction of this attribute
virtual std::shared_ptr<GeomAPI_Dir> dir() = 0;
+ /// Returns the coordinates of this attribute
+ virtual std::shared_ptr<GeomAPI_XYZ> xyz() = 0;
/// Returns the type of this class of attributes
static inline std::string type()
SET(PROJECT_HEADERS
GeomValidators.h
+ GeomValidators_ConstructionComposite.h
+ GeomValidators_Edge.h
+ GeomValidators_EdgeOrVertex.h
+ GeomValidators_Face.h
GeomValidators_Positive.h
+ GeomValidators_Tools.h
)
SET(PROJECT_SOURCES
+ GeomValidators_ConstructionComposite.cpp
+ GeomValidators_Edge.cpp
+ GeomValidators_EdgeOrVertex.cpp
+ GeomValidators_Face.cpp
GeomValidators_Positive.cpp
+ GeomValidators_Tools.cpp
)
SET(PROJECT_LIBRARIES
ModelAPI
- Events
+ Events
+ GeomAPI
)
-ADD_DEFINITIONS(-DGEOMVALIDATORS_EXPORTS)
+ADD_DEFINITIONS(-DGEOMVALIDATORS_EXPORTS ${CAS_DEFINITIONS})
ADD_LIBRARY(GeomValidators SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
TARGET_LINK_LIBRARIES(GeomValidators ${PROJECT_LIBRARIES})
INCLUDE_DIRECTORIES(
- ../ModelAPI
- ../Events
+ ${CAS_INCLUDE_DIRS}
+ ${CMAKE_SOURCE_DIR}/src/ModelAPI
+ ${CMAKE_SOURCE_DIR}/src/Events
+ ${CMAKE_SOURCE_DIR}/src/GeomAPI
+ ${CMAKE_SOURCE_DIR}/src/GeomDataAPI
)
INSTALL(TARGETS GeomValidators DESTINATION plugins)
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#include "GeomValidators_ConstructionComposite.h"
+
+#include "ModelAPI_AttributeSelection.h"
+#include "ModelAPI_ResultConstruction.h"
+#include "ModelAPI_CompositeFeature.h"
+
+bool GeomValidators_ConstructionComposite::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
+{
+ bool aValid = false;
+ AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (theAttribute);
+ if (aSelectionAttr.get() == NULL)
+ return aValid;
+
+ ResultPtr aResult = aSelectionAttr->context();
+ GeomShapePtr aShape = aSelectionAttr->value();
+ // global selection should be ignored, the filter processes only selected sub-shapes
+ // that means, that the shape of the context result is equal to the shape value
+ ///*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
+ if (aResult.get() != NULL) {
+ GeomShapePtr aShapePtr = aResult->shape();
+ // it is important to call isEqual of the shape of result.
+ // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is
+ // GeomAPI_Shape. It is important to use the realization of the isEqual method from
+ // GeomAPI_Vertex class
+ aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape);
+ }
+ if (!aValid) {
+ ResultConstructionPtr aConstr =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
+ if (aConstr != NULL) {
+ // it provides selection only on compositie features, construction without composite
+ // feature is not selectable
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
+ CompositeFeaturePtr aComposite =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
+ aValid = aComposite && aComposite->numberOfSubs() > 0;
+ }
+ else {
+ // non-construction results should be accepted by this filter, e.g. body results
+ aValid = true;
+ }
+ }
+ return aValid;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_ConstructionComposite.h
+// Created: 20 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef GeomValidators_ConstructionComposite_H
+#define GeomValidators_ConstructionComposite_H
+
+#include "GeomValidators.h"
+#include "ModelAPI_AttributeValidator.h"
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class GeomValidators_ConstructionComposite : public ModelAPI_AttributeValidator
+{
+ public:
+ GEOMVALIDATORS_EXPORT GeomValidators_ConstructionComposite() {}
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+
+#include "GeomValidators_Edge.h"
+#include "GeomValidators_Tools.h"
+
+#include <GeomAPI_Curve.h>
+#include <Events_Error.h>
+#include <ModelAPI_Result.h>
+
+#include <StdSelect_TypeOfEdge.hxx>
+
+#include <string>
+#include <map>
+
+
+typedef std::map<std::string, GeomValidators_Edge::TypeOfEdge> EdgeTypes;
+static EdgeTypes MyEdgeTypes;
+
+GeomValidators_Edge::TypeOfEdge GeomValidators_Edge::edgeType(const std::string& theType)
+{
+ if (MyEdgeTypes.size() == 0) {
+ MyEdgeTypes["line"] = Line;
+ MyEdgeTypes["circle"] = Circle;
+ }
+ std::string aType = std::string(theType.c_str());
+ if (MyEdgeTypes.find(aType) != MyEdgeTypes.end())
+ return MyEdgeTypes[aType];
+
+ Events_Error::send("Edge type defined in XML is not implemented!");
+ return AnyEdge;
+}
+
+bool GeomValidators_Edge::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
+{
+ bool aValid = false;
+
+ TypeOfEdge anEdgeType = AnyEdge;
+ if (theArguments.size() == 1) {
+ std::string anArgument = theArguments.front();
+ anEdgeType = edgeType(anArgument);
+ }
+
+ ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
+ if (anObject.get() != NULL) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ if (aResult.get() != NULL) {
+ GeomShapePtr aShape = aResult->shape();
+ if (aShape.get() != NULL && aShape->isEdge()) {
+ aValid = anEdgeType == AnyEdge;
+ if (!aValid) {
+ bool isCircle = GeomAPI_Curve(aShape).isCircle();
+ aValid = (isCircle && anEdgeType == Circle) ||
+ (!isCircle && anEdgeType == Line);
+ }
+ }
+ }
+ }
+ else {
+ //AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ }
+ return aValid;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_Edge.h
+// Created: 19 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef GeomValidators_Edge_H
+#define GeomValidators_Edge_H
+
+#include "GeomValidators.h"
+#include "ModelAPI_AttributeValidator.h"
+
+#include <string>
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class GeomValidators_Edge : public ModelAPI_AttributeValidator
+{
+ public:
+ // the edge type
+ enum TypeOfEdge
+ {
+ AnyEdge,
+ Line,
+ Circle
+ };
+
+ public:
+ GEOMVALIDATORS_EXPORT GeomValidators_Edge() {}
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+protected:
+ /// Convert string to TypeOfEdge value
+ /// \param theType a string value
+ static TypeOfEdge edgeType(const std::string& theType);
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+
+#include "GeomValidators_EdgeOrVertex.h"
+#include "GeomValidators_Tools.h"
+#include "GeomValidators_Edge.h"
+
+#include "ModelAPI_AttributeRefAttr.h"
+#include "ModelAPI_Result.h"
+
+#include <ModelAPI_Session.h>
+
+#include <GeomAPI_Curve.h>
+#include <GeomDataAPI_Point2D.h>
+
+#include <Events_Error.h>
+
+#include <StdSelect_TypeOfEdge.hxx>
+
+#include <QString>
+#include <QMap>
+
+
+bool GeomValidators_EdgeOrVertex::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
+{
+ bool aValid = false;
+
+ // 1. check whether the attribute is a linear edge
+ // there is a check whether the feature contains a point and a linear edge or two point values
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+
+ const GeomValidators_Edge* aLinearEdgeValidator =
+ dynamic_cast<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
+
+ std::list<std::string> anArguments;
+ anArguments.push_back("line");
+ aValid = aLinearEdgeValidator->isValid(theAttribute, anArguments);
+ if (!aValid) {
+ //2. check whether the attribute is a vertex
+ ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
+ if (anObject.get() != NULL) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ if (aResult.get() != NULL) {
+ GeomShapePtr aShape = aResult->shape();
+ if (aShape.get() != NULL) {
+ aValid = aShape->isVertex();
+ }
+ }
+ }
+ else {
+ AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ if (anAttr.get() != NULL) {
+ AttributePtr aRefAttr = anAttr->attr();
+ aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::type();
+ }
+ }
+ }
+ return aValid;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_EdgeOrVertex.h
+// Created: 19 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef GeomValidators_EdgeOrVertex_H
+#define GeomValidators_EdgeOrVertex_H
+
+#include "GeomValidators.h"
+#include "ModelAPI_AttributeValidator.h"
+
+#include <StdSelect_TypeOfEdge.hxx>
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class GeomValidators_EdgeOrVertex : public ModelAPI_AttributeValidator
+{
+ public:
+ GEOMVALIDATORS_EXPORT GeomValidators_EdgeOrVertex() {}
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+
+#include "GeomValidators_Face.h"
+#include "GeomValidators_Tools.h"
+
+#include "ModelAPI_AttributeSelection.h"
+
+#include <GeomAPI_Face.h>
+
+#include <Events_Error.h>
+
+#include <QString>
+#include <QMap>
+
+typedef std::map<std::string, GeomAbs_SurfaceType> FaceTypes;
+static FaceTypes MyFaceTypes;
+
+GeomAbs_SurfaceType GeomValidators_Face::faceType(const std::string& theType)
+{
+ if (MyFaceTypes.size() == 0) {
+ MyFaceTypes["plane"] = GeomAbs_Plane;
+ MyFaceTypes["cylinder"] = GeomAbs_Cylinder;
+ }
+ std::string aType = std::string(theType.c_str());
+ if (MyFaceTypes.find(aType) != MyFaceTypes.end())
+ return MyFaceTypes[aType];
+
+ Events_Error::send("Face type defined in XML is not implemented!");
+ return GeomAbs_Plane;
+}
+
+bool GeomValidators_Face::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
+{
+ bool aValid = false;
+
+ GeomAbs_SurfaceType aFaceType = GeomAbs_Plane;
+ if (theArguments.size() == 1) {
+ std::string anArgument = theArguments.front();
+ aFaceType = faceType(anArgument);
+ }
+
+ ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
+ if (anObject.get() != NULL) {
+ AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (theAttribute);
+ std::shared_ptr<GeomAPI_Shape> aGeomShape = aSelectionAttr->value();
+ std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
+ if (aGeomFace.get() != NULL) {
+ switch(aFaceType) {
+ case GeomAbs_Plane:
+ aValid = aGeomFace->isPlanar();
+ break;
+ case GeomAbs_Cylinder:
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ else
+ aValid = true; // an empty face selected is valid.
+ return aValid;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_Face.h
+// Created: 20 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef GeomValidators_Face_H
+#define GeomValidators_Face_H
+
+#include "GeomValidators.h"
+#include "ModelAPI_AttributeValidator.h"
+
+#include <GeomAbs_SurfaceType.hxx>
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class GeomValidators_Face : public ModelAPI_AttributeValidator
+{
+ public:
+ GEOMVALIDATORS_EXPORT GeomValidators_Face() {}
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+protected:
+ /// Convert string to TypeOfFace value
+ /// \param theType a string value
+ GEOMVALIDATORS_EXPORT static GeomAbs_SurfaceType faceType(const std::string& theType);
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_Tools.cpp
+// Created: 06 Aug 2014
+// Author: Vitaly Smetannikov
+
+#include "GeomValidators_Tools.h"
+
+#include "ModelAPI_AttributeRefAttr.h"
+#include "ModelAPI_AttributeSelection.h"
+#include "ModelAPI_AttributeReference.h"
+
+namespace GeomValidators_Tools {
+
+ ObjectPtr getObject(const AttributePtr& theAttribute)
+ {
+ ObjectPtr anObject;
+ std::string anAttrType = theAttribute->attributeType();
+ if (anAttrType == ModelAPI_AttributeRefAttr::type()) {
+ AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ if (anAttr != NULL && anAttr->isObject())
+ anObject = anAttr->object();
+ }
+ if (anAttrType == ModelAPI_AttributeSelection::type()) {
+ AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ if (anAttr != NULL && anAttr->isInitialized())
+ anObject = anAttr->context();
+ }
+ if (anAttrType == ModelAPI_AttributeReference::type()) {
+ AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+ if (anAttr.get() != NULL && anAttr->isInitialized())
+ anObject = anAttr->value();
+ }
+ return anObject;
+ }
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_Tools.h
+// Created: 23 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef GeomValidators_Tools_HeaderFile
+#define GeomValidators_Tools_HeaderFile
+
+#include "GeomValidators.h"
+#include "ModelAPI_Object.h"
+#include "ModelAPI_Attribute.h"
+
+
+namespace GeomValidators_Tools
+{
+ // Returns the object from the attribute
+ /// \param theObj an object
+ GEOMVALIDATORS_EXPORT ObjectPtr getObject(const AttributePtr& theAttribute);
+
+};
+
+#endif
{
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
myRef->Append(aData->label().Father()); // store label of the object
+ // do it before the transaction finish to make just created/removed objects know dependencies
+ // and reference from composite feature is removed automatically
+ FeaturePtr anOwnerFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
+ if (anOwnerFeature.get()) {
+ aData->addBackReference(anOwnerFeature, id());
+ }
owner()->data()->sendAttributeUpdated(this);
}
if(!theObject)
return;
if (!myIsInitialized || value() != theObject) {
- std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
- theObject->data());
- TDF_Label anObjLab = aData->label().Father(); // object label
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
+ theObject->data());
+ TDF_Label anObjLab = aData->label().Father(); // object label
if (owner()->document() == theObject->document()) { // same document, use reference attribute
TDF_Tool::Entry(anObjLab, anEntry);
TDataStd_AsciiString::Set(myRef->Label(), anEntry);
}
+ // do it before the transaction finish to make just created/removed objects know dependencies
+ // and reference from composite feature is removed automatically
+ FeaturePtr anOwnerFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
+ if (anOwnerFeature.get()) {
+ aData->addBackReference(anOwnerFeature, id());
+ }
owner()->data()->sendAttributeUpdated(this);
}
TDF_Label aSelLab = selectionLabel();
aSelLab.ForgetAttribute(kSIMPLE_REF_ID);
aSelLab.ForgetAttribute(kCONSTUCTION_SIMPLE_REF_ID);
+ if (!theContext.get()) {
+ // to keep the reference attribute label
+ TDF_Label aRefLab = myRef.myRef->Label();
+ aSelLab.ForgetAllAttributes(true);
+ myRef.myRef = TDF_Reference::Set(aSelLab, aSelLab);
+ return;
+ }
if (theContext->groupName() == ModelAPI_ResultBody::group()) {
// do not select the whole shape for body:it is already must be in the data framework
if (theContext->shape().get() && theContext->shape()->isEqual(theSubShape)) {
ModelAPI_FeatureValidator.h
ModelAPI_Object.h
ModelAPI_Plugin.h
- ModelAPI_RefAttrValidator.h
ModelAPI_Result.h
ModelAPI_ResultBody.h
ModelAPI_ResultConstruction.h
ModelAPI_ResultGroup.h
ModelAPI_ResultParameters.h
ModelAPI_ResultPart.h
- ModelAPI_ResultValidator.h
ModelAPI_Session.h
ModelAPI_Tools.h
ModelAPI_ShapeValidator.h
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModelAPI_RefAttrValidator.h
-// Created: 5 Aug 2014
-// Author: Vitaly SMETANNIKOV
-
-#ifndef ModelAPI_RefAttrValidator_H
-#define ModelAPI_RefAttrValidator_H
-
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_Object.h>
-#include <ModelAPI_Attribute.h>
-#include <ModelAPI_AttributeValidator.h>
-
-/**\class ModelAPI_RefAttrValidator
- * \ingroup DataModel
- * Used for filtering out the object that can be used for reference attribute value
- */
-class ModelAPI_RefAttrValidator : public ModelAPI_AttributeValidator
-{
-public:
-};
-
-#endif
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModelAPI_ResultValidators.h
-// Created: 23 July 2014
-// Author: Vitaly SMETANNIKOV
-
-#ifndef ModelAPI_ResultValidators_H
-#define ModelAPI_ResultValidators_H
-
-#include "ModelAPI_Validator.h"
-#include "ModelAPI_Object.h"
-
-/**\class ModelAPI_ResultValidator
- * \ingroup DataModel
- * \brief The base class for selection filter for results of features.
- *
- * The referenced arguments of feature is normally results displayed in the viewer or by the
- * selection attribute. This filter allows to filter out the results not usable as this argument.
- */
-class ModelAPI_ResultValidator : public ModelAPI_Validator
-{
-public:
- /// The abstract method for implementation in the specific validator.
- /// \param theObject the checked object as an argument
- /// \returns true if object is OK for this filter
- virtual bool isValid(const ObjectPtr theObject) const = 0;
-};
-
-#endif
ModuleBase_IViewer.h
ModuleBase_WidgetLineEdit.h
ModuleBase_WidgetMultiSelector.h
- ModuleBase_ValidatorFace.h
- ModuleBase_ValidatorLinearEdge.h
- ModuleBase_ValidatorLinearEdgeOrVertex.h
- ModuleBase_ValidatorNoConstructionSubShapes.h
ModuleBase_ViewerFilters.h
ModuleBase_ResultPrs.h
ModuleBase_IViewWindow.h
ModuleBase_DoubleSpinBox.cpp
ModuleBase_WidgetLineEdit.cpp
ModuleBase_WidgetMultiSelector.cpp
- ModuleBase_ValidatorFace.cpp
- ModuleBase_ValidatorLinearEdge.cpp
- ModuleBase_ValidatorLinearEdgeOrVertex.cpp
- ModuleBase_ValidatorNoConstructionSubShapes.cpp
ModuleBase_ViewerFilters.cpp
ModuleBase_ResultPrs.cpp
ModuleBase_WidgetLabel.cpp
ModelAPI
GeomAPI
GeomAlgoAPI
+ GeomValidators
${QT_LIBRARIES}
${CAS_VIEWER}
${CAS_KERNEL}
${CMAKE_SOURCE_DIR}/src/GeomDataAPI
${CMAKE_SOURCE_DIR}/src/GeomAPI
${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI
+ ${CMAKE_SOURCE_DIR}/src/GeomValidators
${SUIT_INCLUDE}
)
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-
-#include "ModuleBase_ValidatorFace.h"
-#include "ModuleBase_WidgetShapeSelector.h"
-
-#include "ModelAPI_AttributeSelection.h"
-
-#include <GeomAPI_Face.h>
-
-#include <Events_Error.h>
-
-#include <QString>
-#include <QMap>
-
-typedef QMap<QString, GeomAbs_SurfaceType> FaceTypes;
-static FaceTypes MyFaceTypes;
-
-GeomAbs_SurfaceType ModuleBase_ValidatorFace::faceType(const std::string& theType)
-{
- if (MyFaceTypes.count() == 0) {
- MyFaceTypes["plane"] = GeomAbs_Plane;
- MyFaceTypes["cylinder"] = GeomAbs_Cylinder;
- }
- QString aType = QString(theType.c_str()).toLower();
- if (MyFaceTypes.contains(aType))
- return MyFaceTypes[aType];
-
- Events_Error::send("Face type defined in XML is not implemented!");
- return GeomAbs_Plane;
-}
-
-bool ModuleBase_ValidatorFace::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const
-{
- bool aValid = false;
-
- GeomAbs_SurfaceType aFaceType = GeomAbs_Plane;
- if (theArguments.size() == 1) {
- std::string anArgument = theArguments.front();
- aFaceType = faceType(anArgument);
- }
-
- ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute);
- if (anObject.get() != NULL) {
- AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
- (theAttribute);
- std::shared_ptr<GeomAPI_Shape> aGeomShape = aSelectionAttr->value();
- std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
- if (aGeomFace.get() != NULL) {
- switch(aFaceType) {
- case GeomAbs_Plane:
- aValid = aGeomFace->isPlanar();
- break;
- case GeomAbs_Cylinder:
- break;
- default:
- break;
- }
- }
- }
- return aValid;
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModuleBase_ValidatorFace.h
-// Created: 20 Mar 2015
-// Author: Natalia ERMOLAEVA
-
-#ifndef ModuleBase_ValidatorFace_H
-#define ModuleBase_ValidatorFace_H
-
-#include "ModuleBase.h"
-#include "ModelAPI_AttributeValidator.h"
-
-#include <GeomAbs_SurfaceType.hxx>
-
-/**
-* \ingroup Validators
-* A validator of selection
-*/
-class ModuleBase_ValidatorFace : public ModelAPI_AttributeValidator
-{
- public:
- MODULEBASE_EXPORT ModuleBase_ValidatorFace() {}
- //! returns true if attribute is valid
- //! \param theAttribute the checked attribute
- //! \param theArguments arguments of the attribute
- MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const;
-protected:
- /// Convert string to TypeOfFace value
- /// \param theType a string value
- static GeomAbs_SurfaceType faceType(const std::string& theType);
-};
-
-#endif
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-
-#include "ModuleBase_ValidatorLinearEdge.h"
-#include "ModuleBase_WidgetShapeSelector.h"
-
-#include <GeomAPI_Curve.h>
-
-#include <Events_Error.h>
-
-#include <StdSelect_TypeOfEdge.hxx>
-
-#include <QString>
-#include <QMap>
-
-
-typedef QMap<QString, ModuleBase_ValidatorLinearEdge::TypeOfEdge> EdgeTypes;
-static EdgeTypes MyEdgeTypes;
-
-ModuleBase_ValidatorLinearEdge::TypeOfEdge ModuleBase_ValidatorLinearEdge::edgeType(const std::string& theType)
-{
- if (MyEdgeTypes.count() == 0) {
- MyEdgeTypes["line"] = Line;
- MyEdgeTypes["circle"] = Circle;
- }
- QString aType = QString(theType.c_str()).toLower();
- if (MyEdgeTypes.contains(aType))
- return MyEdgeTypes[aType];
-
- Events_Error::send("Edge type defined in XML is not implemented!");
- return AnyEdge;
-}
-
-bool ModuleBase_ValidatorLinearEdge::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const
-{
- bool aValid = false;
-
- TypeOfEdge anEdgeType = AnyEdge;
- if (theArguments.size() == 1) {
- std::string anArgument = theArguments.front();
- anEdgeType = edgeType(anArgument);
- }
-
- ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute);
- if (anObject.get() != NULL) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
- if (aResult.get() != NULL) {
- GeomShapePtr aShape = aResult->shape();
- if (aShape.get() != NULL && aShape->isEdge()) {
- aValid = anEdgeType == AnyEdge;
- if (!aValid) {
- bool isCircle = GeomAPI_Curve(aShape).isCircle();
- aValid = (isCircle && anEdgeType == Circle) ||
- (!isCircle && anEdgeType == Line);
- }
- }
- }
- }
- else {
- //AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
- }
- return aValid;
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModuleBase_ValidatorLinearEdge.h
-// Created: 19 Mar 2015
-// Author: Natalia ERMOLAEVA
-
-#ifndef ModuleBase_ValidatorLinearEdge_H
-#define ModuleBase_ValidatorLinearEdge_H
-
-#include "ModuleBase.h"
-#include "ModelAPI_AttributeValidator.h"
-
-/**
-* \ingroup Validators
-* A validator of selection
-*/
-class ModuleBase_ValidatorLinearEdge : public ModelAPI_AttributeValidator
-{
- public:
- // the edge type
- enum TypeOfEdge
- {
- AnyEdge,
- Line,
- Circle
- };
-
- public:
- MODULEBASE_EXPORT ModuleBase_ValidatorLinearEdge() {}
- //! returns true if attribute is valid
- //! \param theAttribute the checked attribute
- //! \param theArguments arguments of the attribute
- MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const;
-protected:
- /// Convert string to TypeOfEdge value
- /// \param theType a string value
- static TypeOfEdge edgeType(const std::string& theType);
-};
-
-#endif
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-
-#include "ModuleBase_ValidatorLinearEdgeOrVertex.h"
-#include "ModuleBase_WidgetShapeSelector.h"
-#include "ModuleBase_ValidatorLinearEdge.h"
-
-#include "ModelAPI_AttributeRefAttr.h"
-
-#include <ModelAPI_Session.h>
-
-#include <GeomAPI_Curve.h>
-#include <GeomDataAPI_Point2D.h>
-
-#include <Events_Error.h>
-
-#include <StdSelect_TypeOfEdge.hxx>
-
-#include <QString>
-#include <QMap>
-
-
-bool ModuleBase_ValidatorLinearEdgeOrVertex::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const
-{
- bool aValid = false;
-
- // 1. check whether the attribute is a linear edge
- // there is a check whether the feature contains a point and a linear edge or two point values
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-
- const ModuleBase_ValidatorLinearEdge* aLinearEdgeValidator =
- dynamic_cast<const ModuleBase_ValidatorLinearEdge*>(aFactory->validator("ModuleBase_ValidatorLinearEdge"));
-
- std::list<std::string> anArguments;
- anArguments.push_back("line");
- aValid = aLinearEdgeValidator->isValid(theAttribute, anArguments);
- if (!aValid) {
- //2. check whether the attribute is a vertex
- ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute);
- if (anObject.get() != NULL) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
- if (aResult.get() != NULL) {
- GeomShapePtr aShape = aResult->shape();
- if (aShape.get() != NULL) {
- aValid = aShape->isVertex();
- }
- }
- }
- else {
- AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
- if (anAttr.get() != NULL) {
- AttributePtr aRefAttr = anAttr->attr();
- aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::type();
- }
- }
- }
- return aValid;
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModuleBase_ValidatorLinearEdgeOrVertex.h
-// Created: 19 Mar 2015
-// Author: Natalia ERMOLAEVA
-
-#ifndef ModuleBase_ValidatorLinearEdgeOrVertex_H
-#define ModuleBase_ValidatorLinearEdgeOrVertex_H
-
-#include "ModuleBase.h"
-#include "ModelAPI_AttributeValidator.h"
-
-#include <StdSelect_TypeOfEdge.hxx>
-
-/**
-* \ingroup Validators
-* A validator of selection
-*/
-class ModuleBase_ValidatorLinearEdgeOrVertex : public ModelAPI_AttributeValidator
-{
- public:
- MODULEBASE_EXPORT ModuleBase_ValidatorLinearEdgeOrVertex() {}
- //! returns true if attribute is valid
- //! \param theAttribute the checked attribute
- //! \param theArguments arguments of the attribute
- MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const;
-};
-
-#endif
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-#include "ModuleBase_ValidatorNoConstructionSubShapes.h"
-
-#include "ModelAPI_AttributeSelection.h"
-#include "ModelAPI_ResultConstruction.h"
-#include "ModelAPI_CompositeFeature.h"
-
-bool ModuleBase_ValidatorNoConstructionSubShapes::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const
-{
- bool aValid = false;
- AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
- (theAttribute);
- if (aSelectionAttr.get() == NULL)
- return aValid;
-
- ResultPtr aResult = aSelectionAttr->context();
- GeomShapePtr aShape = aSelectionAttr->value();
- // global selection should be ignored, the filter processes only selected sub-shapes
- // that means, that the shape of the context result is equal to the shape value
- ///*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
- if (aResult.get() != NULL) {
- GeomShapePtr aShapePtr = aResult->shape();
- // it is important to call isEqual of the shape of result.
- // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is
- // GeomAPI_Shape. It is important to use the realization of the isEqual method from
- // GeomAPI_Vertex class
- aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape);
- }
- if (!aValid) {
- ResultConstructionPtr aConstr =
- std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
- if (aConstr != NULL) {
- // it provides selection only on compositie features, construction without composite
- // feature is not selectable
- FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
- CompositeFeaturePtr aComposite =
- std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
- aValid = aComposite && aComposite->numberOfSubs() > 0;
- }
- else {
- // non-construction results should be accepted by this filter, e.g. body results
- aValid = true;
- }
- }
- return aValid;
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: ModuleBase_ValidatorNoConstructionSubShapes.h
-// Created: 20 Mar 2015
-// Author: Natalia ERMOLAEVA
-
-#ifndef ModuleBase_ValidatorNoConstructionSubShapes_H
-#define ModuleBase_ValidatorNoConstructionSubShapes_H
-
-#include "ModuleBase.h"
-#include "ModelAPI_AttributeValidator.h"
-
-/**
-* \ingroup Validators
-* A validator of selection
-*/
-class ModuleBase_ValidatorNoConstructionSubShapes : public ModelAPI_AttributeValidator
-{
- public:
- MODULEBASE_EXPORT ModuleBase_ValidatorNoConstructionSubShapes() {}
- //! returns true if attribute is valid
- //! \param theAttribute the checked attribute
- //! \param theArguments arguments of the attribute
- MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const;
-};
-
-#endif
public:
/// Constructor
/// \param theParent the parent object
- /// \param theData the widget configuation. The attribute of the model widget is obtained from
+ /// \param theData the widget configuration.
/// \param theParentId is Id of a parent of the current attribute
ModuleBase_WidgetLineEdit(QWidget* theParent,
const Config_WidgetAPI* theData,
bool ModuleBase_WidgetMultiSelector::storeValueCustom() const
{
// the value is stored on the selection changed signal processing
- return true;
+ // A rare case when plugin was not loaded.
+ if(!myFeature)
+ return false;
+ DataPtr aData = myFeature->data();
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+ if (aSelectionListAttr) {
+ // Store shapes type
+ TopAbs_ShapeEnum aCurrentType =
+ ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText());
+ aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
+ }
+ return true;
}
//********************************************************************
if (aSelectionListAttr) {
// Restore shape type
setCurrentShapeType(
- ModuleBase_WidgetShapeSelector::shapeType(aSelectionListAttr->selectionType().c_str()));
+ ModuleBase_WidgetShapeSelector::shapeType(aSelectionListAttr->selectionType().c_str()));
updateSelectionList(aSelectionListAttr);
return true;
}
#include <Events_Message.h>
#include <GeomAPI_Interface.h>
#include <GeomAPI_Shape.h>
+#include <GeomValidators_Tools.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_Validator.h>
-#include <ModelAPI_ResultValidator.h>
#include <ModelAPI_AttributeValidator.h>
#include <ModelAPI_ShapeValidator.h>
//********************************************************************
bool ModuleBase_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject,
- GeomShapePtr theShape) const
+ GeomShapePtr theShape)
{
bool isChanged = false;
FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theSelectedObject);
return false;
}
-ObjectPtr ModuleBase_WidgetShapeSelector::getObject(const AttributePtr& theAttribute)
-{
- ObjectPtr anObject;
- std::string anAttrType = theAttribute->attributeType();
- if (anAttrType == ModelAPI_AttributeRefAttr::type()) {
- AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
- if (anAttr != NULL && anAttr->isObject())
- anObject = anAttr->object();
- }
- if (anAttrType == ModelAPI_AttributeSelection::type()) {
- AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
- if (anAttr != NULL && anAttr->isInitialized())
- anObject = anAttr->context();
- }
- if (anAttrType == ModelAPI_AttributeReference::type()) {
- AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
- if (anAttr.get() != NULL && anAttr->isInitialized())
- anObject = anAttr->value();
- }
- return anObject;
-}
-
-
//********************************************************************
GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const
{
isNameUpdated = true;
}
if (!isNameUpdated) {
- ObjectPtr anObject = getObject(myFeature->attribute(attributeID()));
+ ObjectPtr anObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID()));
if (anObject.get() != NULL) {
std::string aName = anObject->data()->name();
myTextLine->setText(QString::fromStdString(aName));
AttributePtr anAttribute = myFeature->attribute(attributeID());
if (isBackup) {
- myObject = getObject(anAttribute);
+ myObject = GeomValidators_Tools::getObject(anAttribute);
myShape = getShape();
myRefAttribute = NULL;
myIsObject = false;
myIsObject = aRefAttr->isObject();
myRefAttribute = aRefAttr->attr();
}
+ myExternalObject = NULL;
}
else {
storeAttributeValues(myObject, myShape);
if (!myIsObject)
aRefAttr->setAttr(myRefAttribute);
}
+ if (myExternalObject.get()) {
+ DocumentPtr aDoc = myExternalObject->document();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject);
+ if (aFeature.get() != NULL) {
+ aDoc->removeFeature(aFeature);
+ }
+ }
}
}
ModuleBase_ViewerPrs aPrs;
myWorkshop->selection()->fillPresentation(aPrs, theOwner);
ObjectPtr aObject = aPrs.object();
- ObjectPtr aCurrentObject = getObject(myFeature->attribute(attributeID()));
+ ObjectPtr aCurrentObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID()));
if ((!aCurrentObject) && (!aObject))
return false;
/// The methiod called when widget is deactivated
virtual void deactivate();
- // Get the object from the attribute
- /// \param theObj an object
- static ObjectPtr getObject(const AttributePtr& theAttribute);
-
public slots:
/// Activate or deactivate selection
/// the specific type and set the given values
/// \param theSelectedObject an object
/// \param theShape a selected shape, which is used in the selection attribute
- virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const;
+ virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
//----------- Class members -------------
protected:
AttributePtr myRefAttribute;
/// A boolean value whether refAttr uses reference of object
bool myIsObject;
+ /// An external object
+ ObjectPtr myExternalObject;
};
#endif
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
-#include <ModelAPI_ResultValidator.h>
#include <ModelAPI_AttributeValidator.h>
#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
{
}
+//********************************************************************
bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue)
{
bool isDone = false;
return isDone;
}
+//********************************************************************
bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& theOwner)
{
+ // stores the current values of the widget attribute
backupAttributeValue(true);
+ // saves the owner value to the widget attribute
setSelection(theOwner);
+
+ // checks the attribute validity
bool aValid = isValidAttribute();
+ // restores the current values of the widget attribute
backupAttributeValue(false);
return aValid;
return aValid;
}
-//********************************************************************
-bool ModuleBase_WidgetValidated::isValid(ObjectPtr theObj, GeomShapePtr theShape) const
-{
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- std::list<ModelAPI_Validator*> aValidators;
- std::list<std::list<std::string> > anArguments;
- aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
-
- // Check the type of selected object
- std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
- bool isValid = true;
- for (; aValidator != aValidators.end(); aValidator++) {
- const ModelAPI_ResultValidator* aResValidator =
- dynamic_cast<const ModelAPI_ResultValidator*>(*aValidator);
- if (aResValidator) {
- isValid = false;
- if (aResValidator->isValid(theObj)) {
- isValid = true;
- break;
- }
- }
- }
- return isValid;
-}
-
-#define VALIDATOR_FILTER
void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop,
const bool toActivate) const
{
ModuleBase_IViewer* aViewer = theWorkshop->viewer();
-#ifdef VALIDATOR_FILTER
Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter();
if (toActivate)
aViewer->addSelectionFilter(aSelFilter);
else
aViewer->removeSelectionFilter(aSelFilter);
-#else
- // apply filters loaded from the XML definition of the widget
- ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters();
- SelectMgr_ListOfFilter aFactoryFilters;
- aFactory->filters(parentID(), attributeID(), aFactoryFilters);
- SelectMgr_ListIteratorOfListOfFilter aFactoryIt(aFactoryFilters);
- for (; aFactoryIt.More(); aFactoryIt.Next()) {
- Handle(SelectMgr_Filter) aSelFilter = aFactoryIt.Value();
- if (aSelFilter.IsNull())
- continue;
- if (toActivate)
- aViewer->addSelectionFilter(aSelFilter);
- else
- aViewer->removeSelectionFilter(aSelFilter);
- }
-#endif
-}
-
-void ModuleBase_WidgetValidated::selectionFilters(ModuleBase_IWorkshop* theWorkshop,
- SelectMgr_ListOfFilter& theFilters) const
-{
- ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters();
- SelectMgr_ListOfFilter aFilters;
- aFactory->filters(parentID(), attributeID(), aFilters);
- SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
- for (; aIt.More(); aIt.Next()) {
- Handle(SelectMgr_Filter) aSelFilter = aIt.Value();
- if (aSelFilter.IsNull())
- continue;
-
- theFilters.Append(aSelFilter);
- }
}
/// Set the given wrapped value to the current widget
/// This value should be processed in the widget according to the needs
+ /// The method is called by the current operation to process the operation preselection.
+ /// It is redefined to check the value validity and if it is, fill the attribute with by value
/// \param theValue the wrapped widget value
virtual bool setSelection(ModuleBase_ViewerPrs theValue);
// \return true if all validators return that the attribute is valid
bool isValidAttribute() const;
- /// Check the selected with validators if installed
- /// \param theObj the object for checking
- /// \param theShape the shape for checking
- virtual bool isValid(ObjectPtr theObj, GeomShapePtr theShape) const;
-
/// It obtains selection filters from the workshop and activates them in the active viewer
/// \param theWorkshop an active workshop
/// \param toActivate a flag about activation or deactivation the filters
virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) const;
-
- /// Fills the given list with all widget filters.
- /// \param theWorkshop an active workshop
- /// \param theFilters a list of filters
- void selectionFilters(ModuleBase_IWorkshop* theWorkshop,
- SelectMgr_ListOfFilter& theFilters) const;
};
#endif /* MODULEBASE_WIDGETVALIDATED_H_ */
--- /dev/null
+INCLUDE(Common)
+
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events
+ ${PROJECT_SOURCE_DIR}/src/Config
+ ${PROJECT_SOURCE_DIR}/src/ModelAPI
+)
+
+SET(PROJECT_HEADERS
+ ParametersPlugin.h
+ ParametersPlugin_Plugin.h
+ ParametersPlugin_Parameter.h
+)
+
+SET(PROJECT_SOURCES
+ ParametersPlugin_Plugin.cpp
+ ParametersPlugin_Parameter.cpp
+)
+
+SET(XML_RESOURCES
+ plugin-Parameters.xml
+)
+
+SET(PROJECT_LIBRARIES
+ Events
+ Config
+ ModelAPI
+)
+
+ADD_DEFINITIONS(-DPARAMETERSPLUGIN_EXPORTS)
+ADD_LIBRARY(ParametersPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES})
+
+TARGET_LINK_LIBRARIES(ParametersPlugin ${PROJECT_LIBRARIES})
+
+INSTALL(TARGETS ParametersPlugin DESTINATION plugins)
+INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins)
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef PARAMETERSPLUGIN_H
+#define PARAMETERSPLUGIN_H
+
+#if defined PARAMETERSPLUGIN_EXPORTS
+#if defined WIN32
+#define PARAMETERSPLUGIN_EXPORT __declspec( dllexport )
+#else
+#define PARAMETERSPLUGIN_EXPORT
+#endif
+#else
+#if defined WIN32
+#define PARAMETERSPLUGIN_EXPORT __declspec( dllimport )
+#else
+#define PARAMETERSPLUGIN_EXPORT
+#endif
+#endif
+
+#endif
+
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: ParametersPlugin_Parameter.cpp
+// Created: 23 MArch 2015
+// Author: sbh
+
+#include "ParametersPlugin_Parameter.h"
+#include <ModelAPI_AttributeString.h>
+
+ParametersPlugin_Parameter::ParametersPlugin_Parameter()
+{
+}
+
+void ParametersPlugin_Parameter::initAttributes()
+{
+ data()->addAttribute(ParametersPlugin_Parameter::VARIABLE_ID(), ModelAPI_AttributeString::type());
+ data()->addAttribute(ParametersPlugin_Parameter::EXPRESSION_ID(), ModelAPI_AttributeString::type());
+}
+
+void ParametersPlugin_Parameter::execute()
+{
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: ParametersPlugin_Parameter.h
+// Created: 23 MArch 2015
+// Author: sbh
+
+#ifndef PARAMETERSPLUGIN_PARAMETER_H_
+#define PARAMETERSPLUGIN_PARAMETER_H_
+
+#include "ParametersPlugin.h"
+#include <ModelAPI_Feature.h>
+
+class ParametersPlugin_Parameter : public ModelAPI_Feature
+{
+ public:
+ /// Extrusion kind
+ inline static const std::string& ID()
+ {
+ static const std::string MY_EXTRUSION_ID("Parameter");
+ return MY_EXTRUSION_ID;
+ }
+ /// attribute name of references sketch entities list, it should contain a sketch result or
+ /// a pair a sketch result to sketch face
+ inline static const std::string& VARIABLE_ID()
+ {
+ static const std::string MY_VARIABLE_ID("variable");
+ return MY_VARIABLE_ID;
+ }
+
+ /// attribute name of extrusion size
+ inline static const std::string& EXPRESSION_ID()
+ {
+ static const std::string MY_EXPRESSION_ID("expression");
+ return MY_EXPRESSION_ID;
+ }
+
+ /// Returns the kind of a feature
+ PARAMETERSPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = ParametersPlugin_Parameter::ID();
+ return MY_KIND;
+ }
+
+ /// Creates a new part document if needed
+ PARAMETERSPLUGIN_EXPORT virtual void execute();
+
+ /// Request for initialization of data model of the feature: adding all attributes
+ PARAMETERSPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Use plugin manager for features creation
+ ParametersPlugin_Parameter();
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#include <ParametersPlugin_Plugin.h>
+#include <ParametersPlugin_Parameter.h>
+
+#include <ModelAPI_Session.h>
+
+#include <memory>
+
+// the only created instance of this plugin
+static ParametersPlugin_Plugin* MY_PARAMETERSPLUGIN_INSTANCE = new ParametersPlugin_Plugin();
+
+ParametersPlugin_Plugin::ParametersPlugin_Plugin()
+{
+ // register this plugin
+ SessionPtr aSession = ModelAPI_Session::get();
+ aSession->registerPlugin(this);
+}
+
+FeaturePtr ParametersPlugin_Plugin::createFeature(std::string theFeatureID)
+{
+ // TODO: register some features
+ if (theFeatureID == ParametersPlugin_Parameter::ID()) {
+ return FeaturePtr(new ParametersPlugin_Parameter);
+ }
+ return FeaturePtr();
+}
+
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef PARAMETERSPLUGIN_PLUGIN_H_
+#define PARAMETERSPLUGIN_PLUGIN_H_
+
+#include <ParametersPlugin.h>
+#include <ModelAPI_Plugin.h>
+#include <ModelAPI_Feature.h>
+
+/**\class ParametersPlugin_Plugin
+ * TODO: Add documentation
+ */
+class PARAMETERSPLUGIN_EXPORT ParametersPlugin_Plugin : public ModelAPI_Plugin
+{
+ public:
+ /// Creates the feature object of this plugin by the feature string ID
+ virtual FeaturePtr createFeature(std::string theFeatureID);
+
+ public:
+ ParametersPlugin_Plugin();
+};
+
+#endif
+
--- /dev/null
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<plugin>
+ <workbench id="Part">
+ <group id="Parameters">
+ <feature id="Parameter" title="New Variable" tooltip="Creates a variable" icon=":pictures/expression.png">
+ <stringvalue id="variable" label="Name"/>
+ <stringvalue id="expression" icon="Value"/>
+ </feature>
+ </group>
+ </workbench>
+</plugin>
ModuleBase
Config
GeomAPI
+ GeomValidators
${QT_LIBRARIES}
${CAS_KERNEL}
${CAS_SHAPE}
${CMAKE_SOURCE_DIR}/src/SketchPlugin
${CMAKE_SOURCE_DIR}/src/FeaturesPlugin
${CMAKE_SOURCE_DIR}/src/GeomAPI
+ ${CMAKE_SOURCE_DIR}/src/GeomValidators
${CMAKE_SOURCE_DIR}/src/AppElements
${CAS_INCLUDE_DIRS}
${SUIT_INCLUDE}
#include <ModuleBase_FilterMulti.h>
#include <ModuleBase_FilterCustom.h>
#include <ModuleBase_FilterNoConsructionSubShapes.h>
-#include <ModuleBase_ValidatorLinearEdge.h>
-#include <ModuleBase_ValidatorLinearEdgeOrVertex.h>
-#include <ModuleBase_ValidatorFace.h>
-#include <ModuleBase_ValidatorNoConstructionSubShapes.h>
+#include <GeomValidators_Edge.h>
+#include <GeomValidators_EdgeOrVertex.h>
+#include <GeomValidators_Face.h>
+#include <GeomValidators_ConstructionComposite.h>
#include <PartSet_FilterSketchEntity.h>
aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
- aFactory->registerValidator("PartSet_SketchValidator", new PartSet_SketchValidator);
- aFactory->registerValidator("ModuleBase_ValidatorLinearEdge", new ModuleBase_ValidatorLinearEdge);
- aFactory->registerValidator("ModuleBase_ValidatorLinearEdgeOrVertex",
- new ModuleBase_ValidatorLinearEdgeOrVertex);
- aFactory->registerValidator("ModuleBase_ValidatorFace", new ModuleBase_ValidatorFace);
+ aFactory->registerValidator("GeomValidators_Edge", new GeomValidators_Edge);
+ aFactory->registerValidator("GeomValidators_EdgeOrVertex",
+ new GeomValidators_EdgeOrVertex);
+ aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
- aFactory->registerValidator("ModuleBase_ValidatorNoConstructionSubShapes",
- new ModuleBase_ValidatorNoConstructionSubShapes);
+ aFactory->registerValidator("GeomValidators_ConstructionComposite",
+ new GeomValidators_ConstructionComposite);
aFactory->registerValidator("PartSet_SketchEntityValidator",
new PartSet_SketchEntityValidator);
std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
- std::shared_ptr<GeomDataAPI_Dir> anY = 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()));
+ std::shared_ptr<GeomAPI_XYZ> anY = aNorm->xyz()->cross(aX->xyz());
gp_Pnt anOriginPnt(anOrigin->x(), anOrigin->y(), anOrigin->z());
gp_Vec aVec(anOriginPnt, thePoint);
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()));
+ std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
std::shared_ptr<GeomAPI_Pnt2d> aPnt2d =
std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
- return aPnt2d->to3D(aC->pnt(), aX->dir(), aY->dir());
+ return aPnt2d->to3D(aC->pnt(), aX->dir(), aY);
}
ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
if (!theSketch || !thePoint2D)
return aPoint;
+ DataPtr aData = theSketch->data();
std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- theSketch->data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- theSketch->data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
+ aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+ std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
- return thePoint2D->to3D(aC->pnt(), aX->dir(), aY->dir());
+ return thePoint2D->to3D(aC->pnt(), aX->dir(), aY);
}
ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape,
#include <BRep_Tool.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <GeomAbs_CurveType.hxx>
+#include <GeomValidators_Tools.h>
#include <ModuleBase_ISelection.h>
#include <ModuleBase_WidgetShapeSelector.h>
// 1. check whether the object of the attribute is not among the feature attributes
// find the attribute's object
- ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute);
+ ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
// check whether the object is not among other feature attributes
if (anObject.get() != NULL) {
// the function parameter attribute should be skipped
if (anAttr.get() == NULL || anAttr->id() == theAttribute->id())
continue;
- ObjectPtr aCurObject = ModuleBase_WidgetShapeSelector::getObject(anAttr);
+ ObjectPtr aCurObject = GeomValidators_Tools::getObject(anAttr);
if (aCurObject && aCurObject == anObject)
return false;
}
bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments) const
{
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
-
- // it filters only selection list attributes
- if (aSelectionListAttr.get() == NULL)
- return true;
-
- std::string aType = aSelectionListAttr->selectionType().c_str();
-
- // all context objects should be sketch entities
bool isSketchEntities = true;
- int aSize = aSelectionListAttr->size();
- for (int i = 0; i < aSelectionListAttr->size(); i++) {
- AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
- ObjectPtr anObject = aSelectAttr->context();
- FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
- isSketchEntities = aFeature->getKind() == SketchPlugin_Sketch::ID();
+ std::set<std::string> anEntityKinds;
+ std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
+ for (; anIt != aLast; anIt++) {
+ anEntityKinds.insert(*anIt);
}
- return isSketchEntities;
-}
-bool PartSet_SketchValidator::isValid(const ObjectPtr theObject) const
-{
- FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
- return aFeature->getKind() == SketchPlugin_Sketch::ID();
+ std::string anAttributeType = theAttribute->attributeType();
+ if (anAttributeType == ModelAPI_AttributeSelectionList::type()) {
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ // it filters only selection list attributes
+ std::string aType = aSelectionListAttr->selectionType().c_str();
+ // all context objects should be sketch entities
+ int aSize = aSelectionListAttr->size();
+ for (int i = 0; i < aSelectionListAttr->size() && isSketchEntities; i++) {
+ AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+ ObjectPtr anObject = aSelectAttr->context();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
+ }
+ }
+ if (anAttributeType == ModelAPI_AttributeRefAttr::type()) {
+ std::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ isSketchEntities = false;
+ if (aRef->isObject()) {
+ ObjectPtr anObject = aRef->object();
+ if (anObject.get() != NULL) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ if (aFeature.get() != NULL)
+ isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
+ }
+ }
+ }
+
+ return isSketchEntities;
}
#include <ModuleBase_SelectionValidator.h>
#include <ModuleBase_ISelection.h>
-#include <ModelAPI_RefAttrValidator.h>
-#include <ModelAPI_ResultValidator.h>
+#include <ModelAPI_AttributeValidator.h>
/*
* Selector validators
* \ingroup Validators
* A validator which checks that objects selected for feature attributes are different (not the same)
*/
-class PartSet_DifferentObjectsValidator : public ModelAPI_RefAttrValidator
+class PartSet_DifferentObjectsValidator : public ModelAPI_AttributeValidator
{
public:
//! Returns true if the attribute is good for the feature attribute
* \ingroup Validators
* A validator which checks that objects selected for feature attributes are different (not the same)
*/
-class PartSet_SketchEntityValidator : public ModelAPI_RefAttrValidator
+class PartSet_SketchEntityValidator : public ModelAPI_AttributeValidator
{
public:
//! Returns true if the attribute is good for the feature attribute
const std::list<std::string>& theArguments) const;
};
-/**
-* \ingroup Validators
-* A Validator which validates tha selected object is a Sketch
-*/
-class PartSet_SketchValidator : public ModelAPI_ResultValidator
-{
- public:
- /// Returns True if the given object is a sketch
- /// \param theObject an object
- virtual bool isValid(const ObjectPtr theObject) const;
-};
-
#endif
\ No newline at end of file
#include <PartSet_Tools.h>
#include <SketchPlugin_Feature.h>
-bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const
+bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape)
{
ObjectPtr aSelectedObject = theSelectedObject;
aSelectedObject, mySketch);
if (aObj) {
aSelectedObject = aObj;
+ myExternalObject = aObj;
} else
return false;
}
/// the specific type and set the given values
/// \param theSelectedObject an object
/// \param theShape a selected shape, which is used in the selection attribute
- virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const;
+ virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
private:
/// Pointer to a sketch
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
-#include <ModelAPI_RefAttrValidator.h>
-#include <ModelAPI_ResultValidator.h>
#include <PartSet_Tools.h>
#include <SketchPlugin_Feature.h>
-bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const
+bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape)
{
ObjectPtr aSelectedObject = theSelectedObject;
GeomShapePtr aShape = theShape;
if (aObj) {
PartSet_WidgetShapeSelector* that = (PartSet_WidgetShapeSelector*) this;
aSelectedObject = aObj;
+ myExternalObject = aObj;
} else
return false;
} else {
/// the specific type and set the given values
/// \param theSelectedObject an object
/// \param theShape a selected shape, which is used in the selection attribute
- virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const;
+ virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
private:
/// Pointer to a sketch
#include <ModuleBase_Operation.h>
#include <ModuleBase_ViewerPrs.h>
#include <ModuleBase_Tools.h>
+#include <ModuleBase_IModule.h>
#include <GeomAlgoAPI_FaceBuilder.h>
#include <GeomDataAPI_Point.h>
PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
const Config_WidgetAPI* theData,
const std::string& theParentId)
- : ModuleBase_ModelWidget(theParent, theData, theParentId),
+ : ModuleBase_WidgetValidated(theParent, theData, theParentId),
myPreviewDisplayed(false),
myWorkshop(NULL)
{
void PartSet_WidgetSketchLabel::onPlaneSelected()
{
+
XGUI_Selection* aSelection = myWorkshop->selector()->selection();
QList<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
if (!aSelected.empty()) {
ModuleBase_ViewerPrs aPrs = aSelected.first();
- TopoDS_Shape aShape = aPrs.shape();
- if (!aShape.IsNull()) {
- std::shared_ptr<GeomAPI_Dir> aDir = setSketchPlane(aShape);
- if (aDir) {
- erasePreviewPlanes();
+ Handle(SelectMgr_EntityOwner) anOwner = aSelected.first().owner();
+ if (isValid(anOwner)) {
+ setSelection(anOwner);
- if (aPrs.object() && (feature() != aPrs.object())) {
- DataPtr aData = feature()->data();
- AttributeSelectionPtr aSelAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
- (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
- if (aSelAttr) {
- ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs.object());
- if (aRes) {
- GeomShapePtr aShapePtr(new GeomAPI_Shape());
- aShapePtr->setImpl(new TopoDS_Shape(aShape));
- aSelAttr->setValue(aRes, aShapePtr);
- }
+ TopoDS_Shape aShape = aPrs.shape();
+ if (!aShape.IsNull()) {
+ erasePreviewPlanes();
+ DataPtr aData = feature()->data();
+ AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+ if (aSelAttr) {
+ GeomShapePtr aShapePtr = aSelAttr->value();
+ if (aShapePtr.get() == NULL || aShapePtr->isNull()) {
+ std::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
+ aGShape->setImpl(new TopoDS_Shape(aShape));
+ // get plane parameters
+ std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
+ std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+
+ myWorkshop->viewer()->setViewProjection(aDir->x(), aDir->y(), aDir->z());
}
- } else
- myWorkshop->viewer()->setViewProjection(aDir->x(), aDir->y(), aDir->z());
+ }
// Clear text in the label
myLabel->setText("");
myLabel->setToolTip("");
disconnect(myWorkshop->selector(), SIGNAL(selectionChanged()),
this, SLOT(onPlaneSelected()));
+ activateFilters(myWorkshop->module()->workshop(), false);
// Clear selection mode and define sketching mode
- XGUI_Displayer* aDisp = myWorkshop->displayer();
- aDisp->removeSelectionFilter(myFaceFilter);
+ //XGUI_Displayer* aDisp = myWorkshop->displayer();
//aDisp->closeLocalContexts();
emit planeSelected(plane());
setSketchingMode();
myLabel->installEventFilter(this);
}
+void PartSet_WidgetSketchLabel::backupAttributeValue(const bool isBackup)
+{
+ // it is not necessary to save the previous plane value because the plane is chosen once
+ if (!isBackup) {
+ DataPtr aData = feature()->data();
+ AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+ if (aSelAttr) {
+ ResultPtr anEmptyResult;
+ GeomShapePtr anEmptyShape;
+ aSelAttr->setValue(anEmptyResult, anEmptyShape);
+ }
+ }
+}
+
+bool PartSet_WidgetSketchLabel::setSelection(const Handle_SelectMgr_EntityOwner& theOwner)
+{
+ bool isOwnerSet = false;
+
+ ModuleBase_ViewerPrs aPrs;
+ myWorkshop->selector()->selection()->fillPresentation(aPrs, theOwner);
+
+ const TopoDS_Shape& aShape = aPrs.shape();
+ std::shared_ptr<GeomAPI_Dir> aDir;
+
+ if (aPrs.object() && (feature() != aPrs.object())) {
+ DataPtr aData = feature()->data();
+ AttributeSelectionPtr aSelAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+ if (aSelAttr) {
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs.object());
+ if (aRes) {
+ GeomShapePtr aShapePtr(new GeomAPI_Shape());
+ aShapePtr->setImpl(new TopoDS_Shape(aShape));
+ aSelAttr->setValue(aRes, aShapePtr);
+ isOwnerSet = true;
+ }
+ }
+ }
+ else if (!aShape.IsNull()) {
+ aDir = setSketchPlane(aShape);
+ isOwnerSet = aDir;
+ }
+ return isOwnerSet;
+}
+
void PartSet_WidgetSketchLabel::activateCustom()
{
std::shared_ptr<GeomAPI_Pln> aPlane = plane();
if (aPlane) {
//setSketchingMode();
// In order to avoid Opening/Closing of context too often
+ // it can be useful for a delay on the property panel filling
+ // it is possible that it is not necessary anymore, but it requires a check
mySelectionTimer->start(20);
} else {
// We have to select a plane before any operation
XGUI_Displayer* aDisp = myWorkshop->displayer();
//aDisp->openLocalContext();
//aDisp->activateObjects(QIntList());
- if (myFaceFilter.IsNull())
- myFaceFilter = new StdSelect_FaceFilter(StdSelect_Plane);
- aDisp->addSelectionFilter(myFaceFilter);
QIntList aModes;
aModes << TopAbs_FACE;
aDisp->activateObjects(aModes);
myLabel->setToolTip(myTooltip);
connect(myWorkshop->selector(), SIGNAL(selectionChanged()), this, SLOT(onPlaneSelected()));
+ activateFilters(myWorkshop->module()->workshop(), true);
+
aDisp->updateViewer();
}
}
{
// Do not set selection mode if the widget was activated for a small moment
mySelectionTimer->stop();
- XGUI_Displayer* aDisp = myWorkshop->displayer();
- aDisp->removeSelectionFilter(myFaceFilter);
- //aDisp->removeSelectionFilter(mySketchFilter);
+ //XGUI_Displayer* aDisp = myWorkshop->displayer();
//aDisp->closeLocalContexts();
erasePreviewPlanes();
}
std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
aDirX->setValue(aXDir);
- std::shared_ptr<GeomDataAPI_Dir> aDirY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
- aDirY->setValue(aYDir);
std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
return aDir;
}
#include "PartSet.h"
-#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_WidgetValidated.h>
#include <ModuleBase_ViewerFilters.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Dir.h>
#include <GeomAPI_AISObject.h>
-#include <StdSelect_FaceFilter.hxx>
#include <TopoDS_Shape.hxx>
class QLabel;
* A model widget implementation for a label which provides specific behaviour
* for sketcher starting and launching operations
*/
-class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_ModelWidget
+class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
{
Q_OBJECT
public:
void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
protected:
+ /// Creates a backup of the current values of the attribute
+ /// It should be realized in the specific widget because of different
+ /// parameters of the current attribute
+ /// \param isBackup a boolean flag, if true, store values from the attribute
+ /// to backup, otherwise set the backed up values to the attribute
+ virtual void backupAttributeValue(const bool isBackup);
+
+ /// Fills the attribute with the value of the selected owner
+ /// \param theOwner a selected owner
+ virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner);
+
/// Saves the internal parameters to the given feature
/// \return True in success
virtual bool storeValueCustom() const
AISObjectPtr myXYPlane;
bool myPreviewDisplayed;
- Handle(StdSelect_FaceFilter) myFaceFilter;
-
QTimer* mySelectionTimer;
};
SketchPlugin_ConstraintFillet.h
SketchPlugin_ShapeValidator.h
SketchPlugin_Validators.h
- SketchPlugin_ResultValidators.h
)
SET(PROJECT_SOURCES
SketchPlugin_ConstraintFillet.cpp
SketchPlugin_ShapeValidator.cpp
SketchPlugin_Validators.cpp
- SketchPlugin_ResultValidators.cpp
)
SET(PROJECT_LIBRARIES
Config
GeomAPI
GeomAlgoAPI
+ GeomValidators
ModelAPI
SketcherPrs
${CAS_KERNEL}
../GeomAPI
../GeomAlgoAPI
../GeomDataAPI
+ ../GeomValidators
../SketcherPrs
)
}
bool SketchPlugin_Arc::isFixed() {
- return data()->selection(EXTERNAL_ID())->context().get();
+ return data()->selection(EXTERNAL_ID())->context().get() != NULL;
}
bool SketchPlugin_Arc::isFeatureValid()
}
bool SketchPlugin_Circle::isFixed() {
- return data()->selection(EXTERNAL_ID())->context().get();
+ return data()->selection(EXTERNAL_ID())->context().get() != NULL;
}
void SketchPlugin_Circle::attributeChanged(const std::string& theID) {
}
bool SketchPlugin_Line::isFixed() {
- return data()->selection(EXTERNAL_ID())->context().get();
+ return data()->selection(EXTERNAL_ID())->context().get() != NULL;
}
void SketchPlugin_Line::attributeChanged(const std::string& theID) {
#include <SketchPlugin_ConstraintTangent.h>
#include <SketchPlugin_ConstraintVertical.h>
#include <SketchPlugin_Validators.h>
-#include <SketchPlugin_ResultValidators.h>
#include <SketchPlugin_ShapeValidator.h>
#include <Events_Loop.h>
new SketchPlugin_DistanceAttrValidator);
//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);
+
aFactory->registerValidator("SketchPlugin_ShapeValidator",
new SketchPlugin_ShapeValidator);
}
bool SketchPlugin_Point::isFixed() {
- return data()->selection(EXTERNAL_ID())->context().get();
+ return data()->selection(EXTERNAL_ID())->context().get() != NULL;
}
void SketchPlugin_Point::attributeChanged(const std::string& theID) {
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File: Model_ResultValidators.cpp
-// Created: 23 July 2014
-// Author: Vitaly SMETANNIKOV
-
-#include "SketchPlugin_ResultValidators.h"
-
-#include <ModelAPI_Result.h>
-#include <ModelAPI_Tools.h>
-#include <GeomAPI_Curve.h>
-
-ResultPtr result(const ObjectPtr theObject)
-{
- return std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-}
-
-bool SketchPlugin_ResultPointValidator::isValid(const ObjectPtr theObject) const
-{
- ResultPtr aResult = result(theObject);
- if (!aResult)
- return false;
- std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
- return aShape && aShape->isVertex();
-}
-
-bool SketchPlugin_ResultLineValidator::isValid(const ObjectPtr theObject) const
-{
- ResultPtr aResult = result(theObject);
- if (!aResult)
- return false;
- std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
- return aShape && aShape->isEdge() && GeomAPI_Curve(aShape).isLine();
-}
-
-bool SketchPlugin_ResultArcValidator::isValid(const ObjectPtr theObject) const
-{
- ResultPtr aResult = result(theObject);
- if (!aResult)
- return false;
- std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
- return aShape && aShape->isEdge() && GeomAPI_Curve(aShape).isCircle();
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File: Model_ResultValidators.h
-// Created: 23 July 2014
-// Author: Vitaly SMETANNIKOV
-
-#ifndef Model_ResultValidators_H
-#define Model_ResultValidators_H
-
-#include <SketchPlugin.h>
-#include <ModelAPI_ResultValidator.h>
-#include <ModelAPI_Object.h>
-
-/**\class SketchPlugin_ResultPointValidator
- * \ingroup Validators
- * \brief Validator for the points selection
- *
- * Allows to select points only.
- */
-class SketchPlugin_ResultPointValidator : public ModelAPI_ResultValidator
-{
-public:
- /// Returns true if theObject is a point
- SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-/**\class SketchPlugin_ResultLineValidator
- * \ingroup Validators
- * \brief Validator for the linear segments selection
- *
- * Allows to select linear segments only.
- */
-class SketchPlugin_ResultLineValidator : public ModelAPI_ResultValidator
-{
-public:
- /// Returns true if theObject is a line
- SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-/**\class SketchPlugin_ResultArcValidator
- * \ingroup Validators
- * \brief Validator for the circular segments selection
- *
- * Allows to select circular segments only.
- */
-class SketchPlugin_ResultArcValidator : public ModelAPI_ResultValidator
-{
- public:
- /// Returns true if theObject is an arc
- SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-#endif
#include <ModelAPI_Result.h>
#include <ModelAPI_Tools.h>
#include <ModelAPI_AttributeRefAttr.h>
-#include <ModelAPI_ResultValidator.h>
bool SketchPlugin_ShapeValidator::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments) const
{
data()->addAttribute(SketchPlugin_Sketch::ORIGIN_ID(), GeomDataAPI_Point::type());
data()->addAttribute(SketchPlugin_Sketch::DIRX_ID(), GeomDataAPI_Dir::type());
- data()->addAttribute(SketchPlugin_Sketch::DIRY_ID(), GeomDataAPI_Dir::type());
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()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aDirY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
data()->attribute(SketchPlugin_Sketch::NORM_ID()));
for (; aShapeIt != aFeaturesPreview.end(); ++aShapeIt) {
aBigWire->addEdge(*aShapeIt);
}
- aBigWire->setPlane(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir());
+ aBigWire->setPlane(anOrigin->pnt(), aDirX->dir(), aNorm->dir());
std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
aConstr->setShape(aBigWire);
setResult(aConstr);
{
std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(SketchPlugin_Sketch::NORM_ID()));
std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
+ std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
std::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX))
- ->added(aY->dir()->xyz()->multiplied(theY));
+ ->added(aY->xyz()->multiplied(theY));
return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
}
{
std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(SketchPlugin_Sketch::NORM_ID()));
std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
- return thePnt->to2D(aC->pnt(), aX->dir(), aY->dir());
+ std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
+ return thePnt->to2D(aC->pnt(), aX->dir(), aY);
}
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()));
+ return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(aC->pnt(), aX->dir(), aNorm->dir()));
}
void SketchPlugin_Sketch::erase()
std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
aDirX->setValue(aXDir);
- std::shared_ptr<GeomDataAPI_Dir> aDirY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
- aDirY->setValue(aYDir);
std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
}
}
static const std::string MY_DIRX_ID("DirX");
return MY_DIRX_ID;
}
- /// Vector Y inside of the sketch plane
- inline static const std::string& DIRY_ID()
- {
- static const std::string MY_DIRY_ID("DirY");
- return MY_DIRY_ID;
- }
/// Vector Z, normal to the sketch plane
inline static const std::string& NORM_ID()
{
#include "SketchPlugin_ConstraintDistance.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_Validator.h>
-#include <ModelAPI_ResultValidator.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_Session.h>
+
+#include <GeomValidators_Edge.h>
+
#include <GeomDataAPI_Point2D.h>
bool SketchPlugin_DistanceAttrValidator::isValid(
} else {
// 1. check whether the references object is a linear
ObjectPtr anObject = aRefAttr->object();
- const ModelAPI_ResultValidator* anArcValidator =
- dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultArc"));
- bool anArcValid = anArcValidator->isValid(anObject);
- if (anArcValid)
- return false;
- // If the object is not a line then it is accepted. It can be a point feature selected
- const ModelAPI_ResultValidator* aLineValidator =
- dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultLine"));
- bool aLineValid = aLineValidator->isValid(anObject);
- if (!aLineValid)
+ const ModelAPI_AttributeValidator* anEdgeValidator =
+ dynamic_cast<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
+ std::list<std::string> anArguments;
+ anArguments.push_back("circle");
+ bool anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
+ // the circle line is not a valid case
+ if (anEdgeValid)
+ return false;
+
+ anArguments.clear();
+ anArguments.push_back("line");
+ anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
+ // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
+ if (!anEdgeValid)
return true;
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
// If it is a line then we have to check that first attribute id not a line
std::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(aFeature->data(), aParamA);
if (aPoint)
}
return false;
}
-
-//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);
-//
-// 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;
-//}
#define SketchPlugin_Validators_H
#include "SketchPlugin.h"
-#include <ModelAPI_RefAttrValidator.h>
+#include <ModelAPI_AttributeValidator.h>
/**\class SketchPlugin_DistanceAttrValidator
* \ingroup Validators
*
* It just checks that distance is greater than zero.
*/
-class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator
+class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator
{
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;
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
};
-/**\class SketchPlugin_DifferentObjectsValidator
- * \ingroup Validators
- *
- * 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.
- */
-// 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
title="Sketch"
tooltip="Create a new sketch"
icon=":icons/sketch.png">
- <sketch-start-label title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/>
+ <sketch-start-label id="External" title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch">
+ <validator id="GeomValidators_Face" parameters="plane"/>
+ </sketch-start-label>
<!--icon=":pictures/x_point.png"-->
</feature>
<feature id="SketchPoint" title="Point" tooltip="Create a new point" icon=":icons/point.png">
tooltip="Select point, line end point, line, center of circle or arc."
shape_types="edge vertex">
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
- <validator id="ModuleBase_ValidatorLinearEdgeOrVertex"/>
+ <validator id="GeomValidators_EdgeOrVertex"/>
</sketch_shape_selector>/>
<sketch_shape_selector
id="ConstraintEntityB"
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
- <validator id="ModuleBase_ValidatorLinearEdgeOrVertex"/>
+ <validator id="GeomValidators_EdgeOrVertex"/>
</sketch_shape_selector>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
<label title="Select a line on which to calculate length" tooltip="Select a line on which to calculate length"/>
<shape_selector id="ConstraintEntityA" label="Line" tooltip="Select an line"
shape_types="edge" >
- <validator id="SketchPlugin_ResultLine"/>
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
- <validator id="SketchPlugin_ResultLine"/>
+ <validator id="GeomValidators_Edge" parameters="line"/>
</shape_selector>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
<doublevalue_editor label="Value" tooltip="Length" id="ConstraintValue" default="computed">
<label title="Select a circle or an arc on which to calculate radius" tooltip="Select a circle or an arc on which to calculate radius"/>
<shape_selector id="ConstraintEntityA" label="Circle or Arc" tooltip="Select a circle or an arc"
shape_types="edge">
- <validator id="SketchPlugin_ResultArc"/>
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="circle"/>
+ <validator id="GeomValidators_Edge" parameters="circle"/>
</shape_selector>
<sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
<doublevalue_editor label="Value" tooltip="Radius" id="ConstraintValue" default="computed"/>
<feature id="SketchConstraintParallel" title="Parallel" tooltip="Create constraint defining two parallel lines" icon=":icons/parallel.png">
<sketch_constraint_shape_selector id="ConstraintEntityA"
label="First line" tooltip="Select a line" shape_types="edge">
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+ <validator id="GeomValidators_Edge" parameters="line"/>
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
</sketch_constraint_shape_selector>
<sketch_constraint_shape_selector id="ConstraintEntityB" label="Last line" tooltip="Select a line"
shape_types="edge">
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+ <validator id="GeomValidators_Edge" parameters="line"/>
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
</sketch_constraint_shape_selector>
label="First line" tooltip="Select an line"
shape_types="edge">
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+ <validator id="GeomValidators_Edge" parameters="line"/>
</sketch_constraint_shape_selector>
<sketch_constraint_shape_selector id="ConstraintEntityB"
shape_types="edge">
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+ <validator id="GeomValidators_Edge" parameters="line"/>
</sketch_constraint_shape_selector>
<validator id="PartSet_PerpendicularValidator"/>
</feature>
<feature id="SketchConstraintRigid" title="Fixed" tooltip="Fix an object" icon=":icons/fixed.png">
<shape_selector id="ConstraintEntityA" label="Object" tooltip="Select an object"
shape_types="edge vertex">
- <validator id="SketchPlugin_ResultPoint"/>
- <validator id="SketchPlugin_ResultLine"/>
- <validator id="SketchPlugin_ResultArc"/>
+ <validator id="PartSet_SketchEntityValidator" parameters="SketchPoint,SketchLine,SketchCircle,SketchArc"/>
</shape_selector>
<validator id="PartSet_RigidValidator"/>
</feature>
<feature id="SketchConstraintHorizontal" title="Horizontal" tooltip="Create constraint defining horizontal line" icon=":icons/horisontal.png">
<sketch_constraint_shape_selector id="ConstraintEntityA"
label="Line" tooltip="Select a line" shape_types="edge">
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+ <validator id="GeomValidators_Edge" parameters="line"/>
</sketch_constraint_shape_selector>
</feature>
<!-- SketchConstraintVertical -->
<feature id="SketchConstraintVertical" title="Vertical" tooltip="Create constraint defining vertical line" icon=":icons/vertical.png">
<sketch_constraint_shape_selector id="ConstraintEntityA"
label="Line" tooltip="Select a line" shape_types="edge">
- <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+ <validator id="GeomValidators_Edge" parameters="line"/>
</sketch_constraint_shape_selector>
</feature>
<!-- SketchConstraintEqual -->
// Purpose: create/update the normal of workplane
// ============================================================================
Slvs_hEntity SketchSolver_ConstraintGroup::changeNormal(
- std::shared_ptr<ModelAPI_Attribute> theDirX, std::shared_ptr<ModelAPI_Attribute> theDirY,
+ std::shared_ptr<ModelAPI_Attribute> theDirX,
std::shared_ptr<ModelAPI_Attribute> theNorm)
{
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(theNorm);
std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(theDirX);
- std::shared_ptr<GeomDataAPI_Dir> aDirY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(theDirY);
- if (!aDirX || !aDirY || (fabs(aDirX->x()) + fabs(aDirX->y()) + fabs(aDirX->z()) < tolerance)
- || (fabs(aDirY->x()) + fabs(aDirY->y()) + fabs(aDirY->z()) < tolerance))
+ if (!aDirX || (fabs(aDirX->x()) + fabs(aDirX->y()) + fabs(aDirX->z()) < tolerance))
return SLVS_E_UNKNOWN;
+ // calculate Y direction
+ std::shared_ptr<GeomAPI_Dir> aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aDirX->dir())));
// quaternion parameters of normal vector
double qw, qx, qy, qz;
// Get parameters of workplane
std::shared_ptr<ModelAPI_Attribute> aDirX = mySketch->data()->attribute(
SketchPlugin_Sketch::DIRX_ID());
- std::shared_ptr<ModelAPI_Attribute> aDirY = mySketch->data()->attribute(
- SketchPlugin_Sketch::DIRY_ID());
std::shared_ptr<ModelAPI_Attribute> aNorm = mySketch->data()->attribute(
SketchPlugin_Sketch::NORM_ID());
std::shared_ptr<ModelAPI_Attribute> anOrigin = mySketch->data()->attribute(
SketchPlugin_Sketch::ORIGIN_ID());
// Transform them into SolveSpace format
- Slvs_hEntity aNormalWP = changeNormal(aDirX, aDirY, aNorm);
+ Slvs_hEntity aNormalWP = changeNormal(aDirX, aNorm);
if (!aNormalWP)
return false;
Slvs_hEntity anOriginWP = changeEntity(anOrigin);
* on the plane transversed to created normal.
*
* \param[in] theDirX first coordinate axis of the plane
- * \param[in] theDirY second coordinate axis of the plane
* \param[in] theNorm attribute for the normal (used to identify newly created entity)
* \return identifier of created or updated normal
*/
Slvs_hEntity changeNormal(std::shared_ptr<ModelAPI_Attribute> theDirX,
- std::shared_ptr<ModelAPI_Attribute> theDirY,
std::shared_ptr<ModelAPI_Attribute> theNorm);
/** \brief Adds or updates a parameter in the group
SketcherPrs_HVDirection.h
SketcherPrs_Equal.h
SketcherPrs_Tangent.h
+ SketcherPrs_SensitivePoint.h
)
SET(PROJECT_SOURCES
SketcherPrs_HVDirection.cpp
SketcherPrs_Equal.cpp
SketcherPrs_Tangent.cpp
+ SketcherPrs_SensitivePoint.cpp
)
SET(PROJECT_LIBRARIES
${CAS_VIEWER}
${CAS_SHAPE}
${CAS_TKTopAlgo}
+ ${CAS_TKOpenGl}
)
+IF(WIN32)
+ SET(PROJECT_LIBRARIES ${PROJECT_LIBRARIES} opengl32)
+ELSE()
+ SET(PROJECT_LIBRARIES ${PROJECT_LIBRARIES} GL)
+ENDIF()
+
+
SET(PROJECT_PICTURES
icons/parallel.png
icons/perpendicular.png
icons/tangent.png
)
-ADD_DEFINITIONS(-DCONSTRAINTS_EXPORTS ${CAS_DEFINITIONS})
+ADD_DEFINITIONS(-DSKETCHERPRS_EXPORTS ${CAS_DEFINITIONS})
ADD_LIBRARY(SketcherPrs SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
INCLUDE_DIRECTORIES(
myPntArray->AddVertex(0., 0., 0.);
}
-void SketcherPrs_Equal::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
- const Handle(Prs3d_Presentation)& thePresentation,
- const Standard_Integer theMode)
+bool SketcherPrs_Equal::updatePoints(double theStep) const
{
- prepareAspect();
-
ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+ if (SketcherPrs_Tools::getShape(aObj1).get() == NULL)
+ return false;
+ if (SketcherPrs_Tools::getShape(aObj2).get() == NULL)
+ return false;
- std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
- if (aLine1.get() == NULL)
- return;
-
- std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getShape(aObj2);
- if (aLine2.get() == NULL)
- return;
-
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
- gp_Pnt aP1 = aMgr->getPosition(aObj1, this);
- gp_Pnt aP2 = aMgr->getPosition(aObj2, this);
-
- Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
- aGroup->SetPrimitivesAspect(myAspect);
+ gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep);
+ gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
myPntArray->SetVertice(1, aP1);
myPntArray->SetVertice(2, aP2);
- aGroup->AddPrimitiveArray(myPntArray);
+ return true;
}
void SketcherPrs_Equal::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
DEFINE_STANDARD_RTTI(SketcherPrs_Equal)
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);
virtual const char* iconName() const { return "equal.png"; }
virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
+
+ /// Update myPntArray according to presentation positions
+ /// \return true in case of success
+ virtual bool updatePoints(double theStep) const;
};
#endif
\ No newline at end of file
#define GET_CONSTRAINT_PRS(NAME) \
static AISObjectPtr NAME(SketchPlugin_Constraint* theConstraint, \
- const std::shared_ptr<GeomAPI_Ax3>& thePlane); \
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
/**
myPntArray->AddVertex(0., 0., 0.);
}
-void SketcherPrs_HVDirection::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
- const Handle(Prs3d_Presentation)& thePresentation,
- const Standard_Integer theMode)
+bool SketcherPrs_HVDirection::updatePoints(double theStep) const
{
- prepareAspect();
-
- ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
- std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
- if (aLine1.get() == NULL)
- return;
+ ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+ if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
+ return false;
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
- gp_Pnt aP1 = aMgr->getPosition(aObj1, this);
-
- Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
- aGroup->SetPrimitivesAspect(myAspect);
+ gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep);
myPntArray->SetVertice(1, aP1);
- aGroup->AddPrimitiveArray(myPntArray);
+ return true;
}
void SketcherPrs_HVDirection::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
DEFINE_STANDARD_RTTI(SketcherPrs_HVDirection)
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);
-
virtual const char* iconName() const { return myIsHorisontal? "horisontal.png" : "vertical.png"; }
/// Redefine this function in order to add additiona lines of constraint base
/// \param theColor a color of additiona lines
virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
+ /// Update myPntArray according to presentation positions
+ /// \return true in case of success
+ virtual bool updatePoints(double theStep) const;
+
private:
bool myIsHorisontal;
};
{
myPntArray = new Graphic3d_ArrayOfPoints(2);
myPntArray->AddVertex(0., 0., 0.);
- 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)
-{
- prepareAspect();
+bool SketcherPrs_Parallel::updatePoints(double theStep) const
+{
ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+ if (SketcherPrs_Tools::getShape(aObj1).get() == NULL)
+ return false;
+ if (SketcherPrs_Tools::getShape(aObj2).get() == NULL)
+ return false;
- std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
- if (aLine1.get() == NULL)
- return;
-
- std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getShape(aObj2);
- if (aLine2.get() == NULL)
- return;
-
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
- gp_Pnt aP1 = aMgr->getPosition(aObj1, this);
- gp_Pnt aP2 = aMgr->getPosition(aObj2, this);
-
- Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
- aGroup->SetPrimitivesAspect(myAspect);
+ gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep);
+ gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
myPntArray->SetVertice(1, aP1);
myPntArray->SetVertice(2, aP2);
- aGroup->AddPrimitiveArray(myPntArray);
+ return true;
}
+
void SketcherPrs_Parallel::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
{
Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
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);
-
virtual const char* iconName() const { return "parallel.png"; }
virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
+
+ /// Update myPntArray according to presentation positions
+ /// \return true in case of success
+ virtual bool updatePoints(double theStep) const;
};
#endif
\ No newline at end of file
myPntArray->AddVertex(0., 0., 0.);
}
-void SketcherPrs_Perpendicular::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
- const Handle(Prs3d_Presentation)& thePresentation,
- const Standard_Integer theMode)
-{
- prepareAspect();
+bool SketcherPrs_Perpendicular::updatePoints(double theStep) const
+{
ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
-
- std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
- if (aLine1.get() == NULL)
- return;
-
- std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getShape(aObj2);
- if (aLine2.get() == NULL)
- return;
+ if (SketcherPrs_Tools::getShape(aObj1).get() == NULL)
+ return false;
+ if (SketcherPrs_Tools::getShape(aObj2).get() == NULL)
+ return false;
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
- gp_Pnt aP1 = aMgr->getPosition(aObj1, this);
- gp_Pnt aP2 = aMgr->getPosition(aObj2, this);
-
- Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
- aGroup->SetPrimitivesAspect(myAspect);
+ gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep);
+ gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
myPntArray->SetVertice(1, aP1);
myPntArray->SetVertice(2, aP2);
- aGroup->AddPrimitiveArray(myPntArray);
+ return true;
}
+
void SketcherPrs_Perpendicular::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
{
Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
DEFINE_STANDARD_RTTI(SketcherPrs_Perpendicular)
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);
-
virtual const char* iconName() const { return "perpendicular.png"; }
/// Redefine this function in order to add additiona lines of constraint base
/// \param thePrs a presentation
/// \param theColor a color of additiona lines
virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
+
+ /// Update myPntArray according to presentation positions
+ /// \return true in case of success
+ virtual bool updatePoints(double theStep) const;
};
#endif
\ No newline at end of file
#include <GeomAPI_Vertex.h>
#include <GeomAPI_Dir.h>
-static const int MyStep = 20;
-
static SketcherPrs_PositionMgr* MyPosMgr = NULL;
}
gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape,
- Handle(SketcherPrs_SymbolPrs) thePrs)
+ Handle(SketcherPrs_SymbolPrs) thePrs,
+ double theStep)
{
std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(theShape);
gp_Pnt aP; // Central point
}
gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl<gp_Dir>());
aShift.Normalize();
- aShift.Multiply(MyStep);
+ aShift.Multiply(theStep);
int aPos = getPositionIndex(theShape, thePrs);
int aM = 1;
if (aPos > 1) {
// Normalize vector along the line
aVec1.Normalize();
- aVec1.Multiply(MyStep);
+ aVec1.Multiply(theStep);
aP.Translate(aVec1.Multiplied(aM));
}
return aP;
/// Returns position of symbol for the given presentation
/// \param theLine constrained object
/// \param thePrs a presentation of constraint
- gp_Pnt getPosition(ObjectPtr theLine, Handle(SketcherPrs_SymbolPrs) thePrs);
+ /// \param theStep step between symbols
+ gp_Pnt getPosition(ObjectPtr theLine, Handle(SketcherPrs_SymbolPrs) thePrs, double theStep = 20);
/// Deletes constraint object from internal structures. Has to be called on constraint delete.
/// \param thePrs a constraint presentation
IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Rigid, SketcherPrs_SymbolPrs);
IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Rigid, SketcherPrs_SymbolPrs);
-static Handle(Image_AlienPixMap) MyPixMap;
+static Handle(Image_AlienPixMap) MyPixMap;
+
+
SketcherPrs_Rigid::SketcherPrs_Rigid(SketchPlugin_Constraint* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane)
myPntArray->AddVertex(0., 0., 0.);
}
-void SketcherPrs_Rigid::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
- const Handle(Prs3d_Presentation)& thePresentation,
- const Standard_Integer theMode)
-{
- prepareAspect();
- ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
- std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
- if (aLine1.get() == NULL)
- return;
+bool SketcherPrs_Rigid::updatePoints(double theStep) const
+{
+ ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+ if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
+ return false;
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
- gp_Pnt aP1 = aMgr->getPosition(aObj1, this);
-
- Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
- aGroup->SetPrimitivesAspect(myAspect);
+ gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep);
myPntArray->SetVertice(1, aP1);
- aGroup->AddPrimitiveArray(myPntArray);
+ return true;
}
+
void SketcherPrs_Rigid::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
{
ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
#define SketcherPrs_Rigid_H
#include "SketcherPrs_SymbolPrs.h"
+#include <ModelAPI_Object.h>
class SketchPlugin_Constraint;
class SketchPlugin_Sketch;
Standard_EXPORT SketcherPrs_Rigid(SketchPlugin_Constraint* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
DEFINE_STANDARD_RTTI(SketcherPrs_Rigid)
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);
-
virtual const char* iconName() const { return "anchor.png"; }
/// Redefine this function in order to add additiona lines of constraint base
/// \param thePrs a presentation
/// \param theColor a color of additiona lines
virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
+
+ /// Update myPntArray according to presentation positions
+ /// \return true in case of success
+ virtual bool updatePoints(double theStep) const;
+
};
#endif
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_SensitivePoint.cpp
+// Created: 24 March 2015
+// Author: Vitaly SMETANNIKOV
+
+
+#include "SketcherPrs_SensitivePoint.h"
+
+#include <Select3D_Projector.hxx>
+#include <Bnd_Box2d.hxx>
+#include <CSLib_Class2d.hxx>
+#include <ElCLib.hxx>
+#include <TopLoc_Location.hxx>
+#include <SelectBasics_ListOfBox2d.hxx>
+
+IMPLEMENT_STANDARD_HANDLE(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity);
+IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity);
+
+SketcherPrs_SensitivePoint::SketcherPrs_SensitivePoint(const Handle(SelectBasics_EntityOwner)& anOwner,
+ const Handle(Graphic3d_ArrayOfPoints)& thePntArray,
+ int theId)
+:Select3D_SensitiveEntity(anOwner), myId(theId), myPntArray(thePntArray)
+{
+ SetSensitivityFactor(4.);
+}
+
+void SketcherPrs_SensitivePoint::Project (const Handle(Select3D_Projector)& aProj)
+{
+ gp_Pnt2d aPoint2d;
+ gp_Pnt aPnt = Point();
+ if(!HasLocation())
+ aProj->Project(aPnt, aPoint2d);
+ else
+ {
+ gp_Pnt aP(aPnt.X(), aPnt.Y(), aPnt.Z());
+ aProj->Project(aP.Transformed(Location().Transformation()), aPoint2d);
+ }
+ myprojpt = aPoint2d;
+}
+
+void SketcherPrs_SensitivePoint::Areas(SelectBasics_ListOfBox2d& boxes)
+{
+ Bnd_Box2d abox;
+ abox.Set(myprojpt);
+ boxes.Append(abox);
+}
+
+Standard_Boolean SketcherPrs_SensitivePoint::Matches(const SelectBasics_PickArgs& thePickArgs,
+ Standard_Real& theMatchDMin,
+ Standard_Real& theMatchDepth)
+{
+ // check coordinate matching
+ Standard_Real aDist = gp_Pnt2d (thePickArgs.X(), thePickArgs.Y()).Distance (myprojpt);
+ if (aDist > thePickArgs.Tolerance() * SensitivityFactor())
+ {
+ return Standard_False;
+ }
+
+ Standard_Real aDepth = ComputeDepth (thePickArgs.PickLine());
+ if (thePickArgs.IsClipped (aDepth))
+ {
+ return Standard_False;
+ }
+
+ theMatchDMin = aDist;
+ theMatchDepth = aDepth;
+ return Standard_True;
+}
+
+Standard_Boolean SketcherPrs_SensitivePoint::Matches(const Standard_Real XMin,
+ const Standard_Real YMin,
+ const Standard_Real XMax,
+ const Standard_Real YMax,
+ const Standard_Real aTol)
+{
+ Bnd_Box2d B;
+ B.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax));
+ B.Enlarge(aTol);
+ return !B.IsOut(myprojpt);
+}
+
+Standard_Boolean SketcherPrs_SensitivePoint::Matches(const TColgp_Array1OfPnt2d& aPoly,
+ const Bnd_Box2d& aBox,
+ const Standard_Real aTol)
+{
+ Standard_Real Umin,Vmin,Umax,Vmax;
+ aBox.Get(Umin,Vmin,Umax,Vmax);
+ CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
+
+ Standard_Integer RES = aClassifier2d.SiDans(myprojpt);
+ if(RES==1) return Standard_True;
+
+ return Standard_False;
+}
+
+gp_Pnt SketcherPrs_SensitivePoint::Point() const
+{
+ return myPntArray->Vertice(myId);
+}
+
+Handle(Select3D_SensitiveEntity) SketcherPrs_SensitivePoint::GetConnected(const TopLoc_Location& aLoc)
+{
+ Handle(SketcherPrs_SensitivePoint) NiouEnt = new SketcherPrs_SensitivePoint(myOwnerId,myPntArray,myId);
+ if(HasLocation()) NiouEnt->SetLocation(Location());
+ NiouEnt->UpdateLocation(aLoc);
+ return NiouEnt;
+}
+
+void SketcherPrs_SensitivePoint::Dump(Standard_OStream& S,const Standard_Boolean /*FullDump*/) const
+{
+ gp_Pnt aPnt = Point();
+ S<<"\tSensitivePoint 3D :";
+ if(HasLocation())
+ S<<"\t\tExisting Location"<<endl;
+
+ S<<"\t\t P3d [ "<<aPnt.X()<<" , "<<aPnt.Y()<<" , "<<aPnt.Z()<<" ]"<<endl;
+ S<<"\t\t P2d [ "<<myprojpt.x<<" , "<<myprojpt.y<<" ]"<<endl;
+}
+
+Standard_Real SketcherPrs_SensitivePoint::ComputeDepth(const gp_Lin& EyeLine) const
+{
+ return ElCLib::Parameter(EyeLine, Point());
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_SensitivePoint.h
+// Created: 24 March 2015
+// Author: Vitaly SMETANNIKOV
+
+#ifndef SketcherPrs_SensitivePoint_H
+#define SketcherPrs_SensitivePoint_H
+
+#include <Select3D_SensitiveEntity.hxx>
+#include <Graphic3d_ArrayOfPoints.hxx>
+#include <Select3D_Pnt2d.hxx>
+#include <Standard_DefineHandle.hxx>
+
+
+DEFINE_STANDARD_HANDLE(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity)
+
+class SketcherPrs_SensitivePoint : public Select3D_SensitiveEntity
+{
+public:
+ //! Constructs a sensitive point object defined by the
+ //! owner OwnerId and the point Point.
+ Standard_EXPORT SketcherPrs_SensitivePoint(const Handle(SelectBasics_EntityOwner)& OwnerId,
+ const Handle(Graphic3d_ArrayOfPoints)& thePntArray, int theId);
+
+ //! Converts the stored 3D point into a 2D point according
+ //! to <aProjector> ; this method is called by the selection Manager.
+ Standard_EXPORT void Project (const Handle(Select3D_Projector)& aProjector) ;
+
+ //! stores in <aresult> the 2D sensitive box which represents
+ //! the point area in the selection process.
+ Standard_EXPORT void Areas (SelectBasics_ListOfBox2d& aresult) ;
+
+ Standard_EXPORT Handle(Select3D_SensitiveEntity) GetConnected (const TopLoc_Location& aLocation) ;
+
+ //! Checks whether the sensitive entity matches the picking
+ //! detection area (close to the picking line).
+ //! For details please refer to base class declaration.
+ Standard_EXPORT Standard_Boolean Matches (const SelectBasics_PickArgs& thePickArgs, Standard_Real& theMatchDMin, Standard_Real& theMatchDepth) ;
+
+ Standard_EXPORT Standard_Boolean Matches (const Standard_Real XMin, const Standard_Real YMin, const Standard_Real XMax, const Standard_Real YMax, const Standard_Real aTol) ;
+
+ Standard_EXPORT virtual Standard_Boolean Matches (const TColgp_Array1OfPnt2d& Polyline, const Bnd_Box2d& aBox, const Standard_Real aTol) ;
+
+ Standard_EXPORT Standard_Real ComputeDepth (const gp_Lin& EyeLine) const;
+
+ //! Returns the point used at the time of construction.
+ Standard_EXPORT gp_Pnt Point() const;
+
+ Standard_EXPORT virtual void Dump (Standard_OStream& S, const Standard_Boolean FullDump = Standard_True) const;
+
+ DEFINE_STANDARD_RTTI(SketcherPrs_SensitivePoint)
+
+private:
+ int myId;
+ Handle(Graphic3d_ArrayOfPoints) myPntArray;
+ Select3D_Pnt2d myprojpt;
+};
+
+
+#endif
\ No newline at end of file
#include <GeomAPI_Edge.h>
#include <Graphic3d_ArrayOfSegments.hxx>
+#include <Graphic3d_BndBox4f.hxx>
#include <SelectMgr_Selection.hxx>
-#include <SelectMgr_EntityOwner.hxx>
#include <Select3D_SensitivePoint.hxx>
+#include <TopLoc_Location.hxx>
+#include <AIS_InteractiveContext.hxx>
+#include <V3d_Viewer.hxx>
+#include <Prs3d_Root.hxx>
+#include <OpenGl_Element.hxx>
+#include <OpenGl_GraphicDriver.hxx>
+#include <OpenGl_Context.hxx>
+#include <OpenGl_View.hxx>
+#include <OpenGl_PointSprite.hxx>
+#include <OpenGl_VertexBuffer.hxx>
+#include <OpenGl_ShaderManager.hxx>
+#include <OpenGl_VertexBufferCompat.hxx>
+#include <OpenGl_GraphicDriver.hxx>
#ifdef WIN32
# define FSEP "\\"
# define FSEP "/"
#endif
+/// Step between icons
+static const double MyDist = 0.03;
+
+/// Function to convert opengl data type
+GLenum toGlDataType (const Graphic3d_TypeOfData theType, GLint& theNbComp)
+{
+ switch (theType) {
+ case Graphic3d_TOD_USHORT:
+ theNbComp = 1;
+ return GL_UNSIGNED_SHORT;
+ case Graphic3d_TOD_UINT:
+ theNbComp = 1;
+ return GL_UNSIGNED_INT;
+ case Graphic3d_TOD_VEC2:
+ theNbComp = 2;
+ return GL_FLOAT;
+ case Graphic3d_TOD_VEC3:
+ theNbComp = 3;
+ return GL_FLOAT;
+ case Graphic3d_TOD_VEC4:
+ theNbComp = 4;
+ return GL_FLOAT;
+ case Graphic3d_TOD_VEC4UB:
+ theNbComp = 4;
+ return GL_UNSIGNED_BYTE;
+ }
+ theNbComp = 0;
+ return GL_NONE;
+}
+
+
+//*******************************************************************
+//! Auxiliary class for Vertex buffer with interleaved attributes.
+class SketcherPrs_VertexBuffer : public OpenGl_VertexBuffer
+{
+
+public:
+
+ //! Create uninitialized VBO..
+ SketcherPrs_VertexBuffer (const Graphic3d_Attribute* theAttribs,
+ const Standard_Integer theStride)
+ : Stride (theStride), NbAttributes(1)
+ {
+
+ memcpy (Attribs, theAttribs, sizeof(Graphic3d_Attribute) * NbAttributes);
+ }
+
+ //! Create uninitialized VBO.
+ SketcherPrs_VertexBuffer (const Graphic3d_Buffer& theAttribs)
+ : Stride (theAttribs.Stride), NbAttributes(1)
+ {
+ memcpy (Attribs, theAttribs.AttributesArray(), sizeof(Graphic3d_Attribute) * NbAttributes);
+ }
+
+ virtual bool HasColorAttribute() const
+ {
+ for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter) {
+ const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+ if (anAttrib.Id == Graphic3d_TOA_COLOR) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ virtual bool HasNormalAttribute() const
+ {
+ for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter) {
+ const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+ if (anAttrib.Id == Graphic3d_TOA_NORM) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ virtual void BindPositionAttribute (const Handle(OpenGl_Context)& theGlCtx) const
+ {
+ if (!OpenGl_VertexBuffer::IsValid()) {
+ return;
+ }
+
+ OpenGl_VertexBuffer::Bind (theGlCtx);
+ GLint aNbComp;
+ const GLubyte* anOffset = OpenGl_VertexBuffer::myOffset;
+ for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter) {
+ const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+ const GLenum aDataType = toGlDataType (anAttrib.DataType, aNbComp);
+ if (aDataType == GL_NONE) {
+ continue;
+ } else if (anAttrib.Id == Graphic3d_TOA_POS) {
+ OpenGl_VertexBuffer::bindAttribute (theGlCtx, Graphic3d_TOA_POS, aNbComp, aDataType, Stride, anOffset);
+ break;
+ }
+
+ anOffset += Graphic3d_Attribute::Stride (anAttrib.DataType);
+ }
+ }
+
+ virtual void BindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const
+ {
+ if (!OpenGl_VertexBuffer::IsValid())
+ return;
+
+ OpenGl_VertexBuffer::Bind (theGlCtx);
+ GLint aNbComp;
+ const GLubyte* anOffset = OpenGl_VertexBuffer::myOffset;
+ for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter)
+ {
+ const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+ const GLenum aDataType = toGlDataType (anAttrib.DataType, aNbComp);
+ if (aDataType == GL_NONE)
+ continue;
+
+ OpenGl_VertexBuffer::bindAttribute (theGlCtx, anAttrib.Id, aNbComp, aDataType, Stride, anOffset);
+ anOffset += Graphic3d_Attribute::Stride (anAttrib.DataType);
+ }
+ }
+
+ virtual void UnbindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const
+ {
+ if (!OpenGl_VertexBuffer::IsValid())
+ return;
+ OpenGl_VertexBuffer::Unbind (theGlCtx);
+
+ for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter) {
+ const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+ OpenGl_VertexBuffer::unbindAttribute (theGlCtx, anAttrib.Id);
+ }
+ }
+
+public:
+
+ Graphic3d_Attribute Attribs[1];
+ Standard_Integer Stride;
+ Standard_Integer NbAttributes;
+};
+
+//**************************************************************
+//! Redefinition of OpenGl_Element
+class SketcherPrs_Element: public OpenGl_Element
+{
+public:
+ SketcherPrs_Element(const Handle(SketcherPrs_SymbolPrs)& theObj) :
+ OpenGl_Element(), myObj(theObj) {}
+
+ virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const
+ {
+ if (!myObj.IsNull())
+ myObj->Render(theWorkspace);
+ }
+
+ virtual void Release (OpenGl_Context* theContext)
+ {
+ if (!myObj.IsNull())
+ myObj->Release(theContext);
+ }
+
+private:
+ Handle(SketcherPrs_SymbolPrs) myObj;
+};
+
+
+//**************************************************************
+//! Definition of call back
+OpenGl_Element* SymbolPrsCallBack(const CALL_DEF_USERDRAW * theUserDraw)
+{
+ Handle(SketcherPrs_SymbolPrs) anIObj = (SketcherPrs_SymbolPrs*)theUserDraw->Data;
+ if (anIObj.IsNull()) {
+ std::cout << "VUserDrawCallback error: null object passed, the custom scene element will not be rendered" << std::endl;
+ }
+ return new SketcherPrs_Element(anIObj);
+}
+
+
+//*****************************************************************************
IMPLEMENT_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject);
IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SymbolPrs, AIS_InteractiveObject);
thePM->AddToImmediateList(aHilightPrs);
}
+void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
+{
+ prepareAspect();
+
+ Handle(AIS_InteractiveContext) aCtx = GetContext();
+ Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(aCtx->CurrentViewer()->Driver());
+ if (!aDriver.IsNull()) {
+ // register the custom element factory function
+ aDriver->UserDrawCallback() = SymbolPrsCallBack;
+ }
+
+ if (!updatePoints(20))
+ return;
+
+ int aNbVertex = myPntArray->VertexNumber();
+ if (myOwner.IsNull()) {
+ myOwner = new SelectMgr_EntityOwner(this);
+ for (int i = 1; i <= aNbVertex; i++) {
+ Handle(SketcherPrs_SensitivePoint) aSP = new SketcherPrs_SensitivePoint(myOwner, myPntArray, i);
+ mySPoints.Append(aSP);
+ }
+ }
+
+ Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePresentation);
+ aGroup->SetPrimitivesAspect(myAspect);
+
+ Graphic3d_BndBox4f& aBnd = aGroup->ChangeBoundingBox();
+ gp_Pnt aVert;
+ aBnd.Clear();
+ for (int i = 1; i <= myPntArray->ItemNumber(); i++) {
+ aVert = myPntArray->Vertice(i);
+ aBnd.Add (Graphic3d_Vec4((float)aVert.X(), (float)aVert.Y(), (float)aVert.Z(), 1.0f));
+ }
+
+ aGroup->UserDraw(this, true);
+ //aGroup->AddPrimitiveArray(myPntArray);
+}
+
void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
const Standard_Integer aMode)
{
ClearSelected();
+ for (int i = 1; i <= mySPoints.Length(); i++)
+ aSelection->Add(mySPoints.Value(i));
+}
+
- if (!myPntArray.IsNull()) {
- Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this);
- for (int i = 1; i <= myPntArray->VertexNumber(); i++) {
- Handle(Select3D_SensitivePoint) aSP = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(i));
- aSelection->Add(aSP);
+void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace) const
+{
+ const OpenGl_AspectMarker* anAspectMarker = theWorkspace->AspectMarker(Standard_True);
+ const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
+ Handle(OpenGl_View) aView = theWorkspace->ActiveView();
+
+ double aScale = aView->Camera()->Scale();
+ if (!updatePoints(MyDist * aScale))
+ return;
+
+ Handle(Graphic3d_Buffer) aAttribs = myPntArray->Attributes();
+
+ if (myVboAttribs.IsNull()) {
+ myVboAttribs = new SketcherPrs_VertexBuffer(*aAttribs);
+ }
+
+ if (!myVboAttribs->init(aCtx, 0, aAttribs->NbElements, aAttribs->Data(), GL_NONE, aAttribs->Stride)) {
+ myVboAttribs->Release (aCtx.operator->());
+ myVboAttribs.Nullify();
+ return;
+ }
+
+ Handle(OpenGl_Texture) aTextureBack = theWorkspace->DisableTexture();
+
+ const Handle(OpenGl_PointSprite)& aSpriteNorm = anAspectMarker->SpriteRes(aCtx);
+
+ if (!aSpriteNorm.IsNull() && !aSpriteNorm->IsDisplayList()) {
+ const bool toHilight = (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) != 0;
+ const Handle(OpenGl_PointSprite)& aSprite = (toHilight && anAspectMarker->SpriteHighlightRes(aCtx)->IsValid())
+ ? anAspectMarker->SpriteHighlightRes(aCtx)
+ : aSpriteNorm;
+ theWorkspace->EnableTexture (aSprite);
+ aCtx->ShaderManager()->BindProgram(anAspectMarker, aSprite, Standard_False, Standard_False, anAspectMarker->ShaderProgramRes(aCtx));
+ const TEL_COLOUR* aLineColor = &anAspectMarker->Color();
+ if (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT)
+ aLineColor = theWorkspace->HighlightColor;
+
+ aCtx->SetColor4fv(*(const OpenGl_Vec4* )(aLineColor->rgb));
+
+
+ myVboAttribs->BindAllAttributes(aCtx);
+ // Textured markers will be drawn with the point sprites
+ aCtx->SetPointSize (anAspectMarker->MarkerSize());
+ aCtx->core11fwd->glEnable (GL_ALPHA_TEST);
+ aCtx->core11fwd->glAlphaFunc (GL_GEQUAL, 0.1f);
+
+ aCtx->core11fwd->glEnable (GL_BLEND);
+ aCtx->core11fwd->glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ aCtx->core11fwd->glDrawArrays (0, 0, myVboAttribs->GetElemsNb());
+
+ aCtx->core11fwd->glDisable (GL_BLEND);
+ aCtx->core11fwd->glDisable (GL_ALPHA_TEST);
+ aCtx->SetPointSize (1.0f);
+ }
+ theWorkspace->EnableTexture (aTextureBack);
+ aCtx->BindProgram (NULL);
+
+ // Update selection position
+ GetContext()->RecomputeSelectionOnly(this);
+}
+
+
+void SketcherPrs_SymbolPrs::Release (OpenGl_Context* theContext)
+{
+ if (!myVboAttribs.IsNull()) {
+ if (theContext) {
+ theContext->DelayedRelease (myVboAttribs);
}
+ myVboAttribs.Nullify();
}
}
+
#ifndef SketcherPrs_SymbolPrs_H
#define SketcherPrs_SymbolPrs_H
+#include "SketcherPrs_SensitivePoint.h"
+
#include <AIS_InteractiveObject.hxx>
#include <GeomAPI_Ax3.h>
#include <Graphic3d_ArrayOfPoints.hxx>
#include <Graphic3d_AspectMarker3d.hxx>
#include <Image_AlienPixMap.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <Select3D_SensitiveEntitySequence.hxx>
#include <Standard_DefineHandle.hxx>
#include <map>
+#include <OpenGl_Workspace.hxx>
+
class SketchPlugin_Constraint;
+class OpenGl_Context;
DEFINE_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject)
Standard_EXPORT SketchPlugin_Constraint* feature() const { return myConstraint; }
+
+ Handle(Graphic3d_ArrayOfPoints) pointsArray() const { return myPntArray; }
+
+ void Render(const Handle(OpenGl_Workspace)& theWorkspace) const;
+
+ void Release (OpenGl_Context* theContext);
+
DEFINE_STANDARD_RTTI(SketcherPrs_SymbolPrs)
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,
/// \param theColor a color of additiona lines
virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const {}
+ /// Update myPntArray according to presentation positions
+ /// \return true in case of success
+ virtual bool updatePoints(double theStep) const { return true; }
+
protected:
/// Constraint feature
SketchPlugin_Constraint* myConstraint;
Handle(Graphic3d_AspectMarker3d) myAspect;
/// Array of symbols positions
- Handle(Graphic3d_ArrayOfPoints) myPntArray;
+ mutable Handle(Graphic3d_ArrayOfPoints) myPntArray;
+
+ Handle(SelectMgr_EntityOwner) myOwner;
private:
/// Static map to collect constraints icons {IconName : IconPixMap}
static std::map<const char*, Handle(Image_AlienPixMap)> myIconsMap;
+ mutable Handle(OpenGl_VertexBuffer) myVboAttribs;
+
+ Select3D_SensitiveEntitySequence mySPoints;
};
#endif
\ No newline at end of file
myPntArray->AddVertex(0., 0., 0.);
}
-void SketcherPrs_Tangent::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
- const Handle(Prs3d_Presentation)& thePresentation,
- const Standard_Integer theMode)
+bool SketcherPrs_Tangent::updatePoints(double theStep) const
{
- prepareAspect();
-
ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+ if (SketcherPrs_Tools::getShape(aObj1).get() == NULL)
+ return false;
+ if (SketcherPrs_Tools::getShape(aObj2).get() == NULL)
+ return false;
- std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
- if (aLine1.get() == NULL)
- return;
-
- std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getShape(aObj2);
- if (aLine2.get() == NULL)
- return;
-
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
- gp_Pnt aP1 = aMgr->getPosition(aObj1, this);
- gp_Pnt aP2 = aMgr->getPosition(aObj2, this);
-
- Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
- aGroup->SetPrimitivesAspect(myAspect);
+ gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep);
+ gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
myPntArray->SetVertice(1, aP1);
myPntArray->SetVertice(2, aP2);
- aGroup->AddPrimitiveArray(myPntArray);
+ return true;
}
void SketcherPrs_Tangent::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
/// \param thePlane a coordinate plane of current sketch
Standard_EXPORT SketcherPrs_Tangent(SketchPlugin_Constraint* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
DEFINE_STANDARD_RTTI(SketcherPrs_Tangent)
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);
virtual const char* iconName() const { return "tangent.png"; }
virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
+
+ /// Update myPntArray according to presentation positions
+ /// \return true in case of success
+ virtual bool updatePoints(double theStep) const;
};
#endif
\ No newline at end of file
<file>pictures/module.png</file>
<file>pictures/shading.png</file>
<file>pictures/wireframe.png</file>
+ <file>pictures/expression.png</file>
</qresource>
</RCC>