ConstructionPlugin_Point.h
ConstructionPlugin_Axis.h
ConstructionPlugin_Plane.h
+ ConstructionPlugin_Validators.h
)
SET(PROJECT_SOURCES
ConstructionPlugin_Point.cpp
ConstructionPlugin_Axis.cpp
ConstructionPlugin_Plane.cpp
+ ConstructionPlugin_Validators.cpp
)
SET(XML_RESOURCES
../ModelAPI
../GeomAPI
../GeomAlgoAPI
+ ../Events
)
#include "ConstructionPlugin_Point.h"
#include "ConstructionPlugin_Axis.h"
#include "ConstructionPlugin_Plane.h"
+#include "ConstructionPlugin_Validators.h"
#include <Config_PropManager.h>
ConstructionPlugin_Plugin::ConstructionPlugin_Plugin()
{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+ aFactory->registerValidator("ConstructionPlugin_ValidatorPointLines",
+ new ConstructionPlugin_ValidatorPointLines());
+
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
+
+ data()->addAttribute(FIRST_LINE(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(SECOND_LINE(), ModelAPI_AttributeSelection::typeId());
}
//==================================================================================================
aShape = createByDistanceOnEdge();
} else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) {
aShape = createByProjection();
+ } else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) {
+ aShape = createByIntersection();
}
if(aShape.get()) {
return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace);
}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByIntersection()
+{
+ // Get first line.
+ AttributeSelectionPtr aFirstLineSelection= selection(FIRST_LINE());
+ GeomShapePtr aFirstLineShape = aFirstLineSelection->value();
+ if(!aFirstLineShape.get()) {
+ aFirstLineShape = aFirstLineSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Edge> aFirstEdge(new GeomAPI_Edge(aFirstLineShape));
+
+ // Get first line.
+ AttributeSelectionPtr aSecondLineSelection= selection(SECOND_LINE());
+ GeomShapePtr aSecondLineShape = aSecondLineSelection->value();
+ if(!aSecondLineShape.get()) {
+ aSecondLineShape = aSecondLineSelection->context()->shape();
+ }
+ std::shared_ptr<GeomAPI_Edge> aSecondEdge(new GeomAPI_Edge(aSecondLineShape));
+
+ return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge);
+}
return MY_CREATION_METHOD_ID;
}
+ /// Attribute name for creation method.
+ inline static const std::string& CREATION_METHOD_BY_LINES_INTERSECTION()
+ {
+ static const std::string MY_CREATION_METHOD_ID("by_lines_intersection");
+ return MY_CREATION_METHOD_ID;
+ }
+
/// Attribute name for X coordinate.
inline static const std::string& X()
{
return ATTR_ID;
}
+ /// Attribute name for seleted first line.
+ inline static const std::string& FIRST_LINE()
+ {
+ static const std::string ATTR_ID("first_line");
+ return ATTR_ID;
+ }
+
+ /// Attribute name for seleted second line.
+ inline static const std::string& SECOND_LINE()
+ {
+ static const std::string ATTR_ID("second_line");
+ return ATTR_ID;
+ }
+
/// Creates a new part document if needed.
CONSTRUCTIONPLUGIN_EXPORT virtual void execute();
std::shared_ptr<GeomAPI_Vertex> createByXYZ();
std::shared_ptr<GeomAPI_Vertex> createByDistanceOnEdge();
std::shared_ptr<GeomAPI_Vertex> createByProjection();
+ std::shared_ptr<GeomAPI_Vertex> createByIntersection();
};
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: ConstructionPlugin_Validators.cpp
+// Created: 04 July 2016
+// Author: Dmitry Bobylev
+
+#include "ConstructionPlugin_Validators.h"
+
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+
+#include <ModelAPI_AttributeSelection.h>
+
+#include <Events_InfoMessage.h>
+
+//==================================================================================================
+bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+
+ AttributeSelectionPtr aLineAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
+
+ GeomShapePtr aLineShape1 = aLineAttribute1->value();
+ ResultPtr aContext1 = aLineAttribute1->context();
+ if(!aContext1.get()) {
+ theError = "One of the attribute not initialized.";
+ return false;
+ }
+ if(!aLineShape1.get()) {
+ aLineShape1 = aContext1->shape();
+ }
+ if(!aLineShape1->isEdge()) {
+ theError = "One of the selected shapes not an edge.";
+ return false;
+ }
+
+ GeomShapePtr aLineShape2 = aLineAttribute2->value();
+ ResultPtr aContext2 = aLineAttribute2->context();
+ if(!aContext2.get()) {
+ return true;
+ }
+ if(!aLineShape2.get()) {
+ aLineShape2 = aContext2->shape();
+ }
+ if(!aLineShape2->isEdge()) {
+ theError = "One of the selected shapes not an edge.";
+ return false;
+ }
+
+ std::shared_ptr<GeomAPI_Edge> aLineEdge1(new GeomAPI_Edge(aLineShape1));
+ std::shared_ptr<GeomAPI_Edge> aLineEdge2(new GeomAPI_Edge(aLineShape2));
+
+ std::shared_ptr<GeomAPI_Lin> aLine1 = aLineEdge1->line();
+ std::shared_ptr<GeomAPI_Lin> aLine2 = aLineEdge2->line();
+
+ if(!aLine1->isCoplanar(aLine2)) {
+ theError = "Selected lines not coplanar.";
+ return false;
+ }
+
+ if(aLine1->isParallel(aLine2)) {
+ theError = "Selected lines are parallel.";
+ return false;
+ }
+
+ return true;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: ConstructionPlugin_Validators.h
+// Created: 04 July 2016
+// Author: Dmitry Bobylev
+
+#ifndef ConstructionPlugin_Validators_H_
+#define ConstructionPlugin_Validators_H_
+
+#include <ModelAPI_AttributeValidator.h>
+
+/// \class ConstructionPlugin_ValidatorPointLines
+/// \ingroup Validators
+/// \brief A validator for selection lines for point by intersection..
+class ConstructionPlugin_ValidatorPointLines: public ModelAPI_AttributeValidator
+{
+public:
+ //! \return True if the attribute is valid.
+ //! \param[in] theAttribute the checked attribute.
+ //! \param[in] theArguments arguments of the attribute.
+ //! \param[out] theError error message.
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const;
+};
+
+#endif
\ No newline at end of file
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
</box>
+ <box id="by_lines_intersection"
+ title="By intersection"
+ tooltip="Point by intersection of two coplanar lines."
+ icon="icons/Construction/point_by_lines_intersection_32x32.png">
+ <shape_selector id="first_line"
+ label="First line"
+ tooltip="First line."
+ icon="icons/Construction/point.png"
+ shape_types="edge">
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
+ <validator id="ConstructionPlugin_ValidatorPointLines" parameters="second_line"/>
+ </shape_selector>
+ <shape_selector id="second_line"
+ label="Second line"
+ tooltip="Second line."
+ icon="icons/Construction/point.png"
+ shape_types="edge">
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
+ <validator id="ConstructionPlugin_ValidatorPointLines" parameters="first_line"/>
+ </shape_selector>
+ </box>
</toolbox>
</source>
return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z()));
}
+bool GeomAPI_Lin::isParallel(const std::shared_ptr<GeomAPI_Lin> theLin) const
+{
+ return MY_LIN->Direction().IsParallel(theLin->impl<gp_Lin>().Direction(), Precision::Confusion()) == Standard_True;
+}
+
+bool GeomAPI_Lin::isCoplanar(const std::shared_ptr<GeomAPI_Lin> theLin) const
+{
+ if(MY_LIN->SquareDistance(theLin->impl<gp_Lin>()) > Precision::Confusion()) {
+ return false;
+ }
+
+ return true;
+}
GEOMAPI_EXPORT
const std::shared_ptr<GeomAPI_Pnt> project(
const std::shared_ptr<GeomAPI_Pnt>& thePoint) const;
+
+ /// \return true if lines are parallel.
+ GEOMAPI_EXPORT
+ bool isParallel(const std::shared_ptr<GeomAPI_Lin> theLin) const;
+
+ /// \return true if lines are coplanar.
+ GEOMAPI_EXPORT
+ bool isCoplanar(const std::shared_ptr<GeomAPI_Lin> theLin) const;
};
#endif
return aVertex;
}
- gp_Lin aLin1 = theEdge1->line()->impl<gp_Lin>();
- gp_Lin aLin2 = theEdge2->line()->impl<gp_Lin>();
+ std::shared_ptr<GeomAPI_Lin> aLin1 = theEdge1->line();
+ std::shared_ptr<GeomAPI_Lin> aLin2 = theEdge2->line();
- if(aLin1.Distance(aLin2) > Precision::Confusion()) {
- return aVertex;
- }
-
- Handle(Geom_Line) aLine1 = new Geom_Line(aLin1);
- Handle(Geom_Line) aLine2 = new Geom_Line(aLin2);
-
- GeomAPI_ExtremaCurveCurve anExtrema(aLine1, aLine2);
+ std::shared_ptr<GeomAPI_Pnt> aPnt = aLin1->intersect(aLin2);
- Standard_Integer aNbExtrema = anExtrema.NbExtrema();
-
- if(aNbExtrema == 0) {
+ if(!aPnt.get()) {
return aVertex;
}
- gp_Pnt aPnt1, aPnt2;
- for(Standard_Integer anIndex = 1; anIndex <= aNbExtrema; ++anIndex) {
- if(anExtrema.Distance(anIndex) <= Precision::Confusion()) {
- anExtrema.Points(anIndex, aPnt1, aPnt2);
- }
- }
-
- aVertex.reset(new GeomAPI_Vertex(aPnt1.X(), aPnt1.Y(), aPnt1.Z()));
+ aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z()));
return aVertex;
}