if(initialize()) {
setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
}
-}
+}*/
//==================================================================================================
ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
if(initialize()) {
GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
-
+ /*
if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
// If first object is vertex and second object is face then set by projection.
setByProjection(theObject1, theObject2);
} else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
// If both objects are edges then set by lines intersection.
setByLinesIntersection(theObject1, theObject2);
- } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
+ } else */if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
// If first object is edge and second object is face then set by line and plane intersection.
setByLineAndPlaneIntersection(theObject1, theObject2);
}
}
-}*/
+}
//==================================================================================================
ConstructionAPI_Point::~ConstructionAPI_Point()
fillAttribute(theX, myx);
fillAttribute(theY, myy);
fillAttribute(theZ, myz);
+ fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
execute(false);
}
fillAttribute(theEdge2, mysecondLine);
execute();
-}
+}*/
//==================================================================================================
void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
const ModelHighAPI_Selection& theFace)
{
- fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
+ fillAttribute(
+ ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
fillAttribute(theEdge, myintersectionLine);
fillAttribute(theFace, myintersectionPlane);
-
+ fillAttribute("", useOffset()); // not used by default
execute();
-}*/
+}
//==================================================================================================
void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
{
- // TODO: all types of points
-
FeaturePtr aBase = feature();
const std::string& aDocName = theDumper.name(aBase->document());
-
- AttributeDoublePtr anAttrX = aBase->real(ConstructionPlugin_Point::X());
- AttributeDoublePtr anAttrY = aBase->real(ConstructionPlugin_Point::Y());
- AttributeDoublePtr anAttrZ = aBase->real(ConstructionPlugin_Point::Z());
- theDumper << aBase << " = model.addPoint(" << aDocName << ", "
- << anAttrX << ", " << anAttrY << ", " << anAttrZ << ")" << std::endl;
+ const std::string& aMeth = creationMethod()->value();
+
+ // common part
+ theDumper << aBase << " = model.addPoint(" << aDocName << ", ";
+
+ if (aMeth == "" || // default is XYZ
+ aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) {
+ theDumper << x() << ", " << y() << ", " << z() << ")" << std::endl;
+ } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
+ theDumper << intersectionLine() << ", " <<intersectionPlane() ;
+ if (!useOffset()->value().empty()) { // call method with defined offset
+ theDumper << ", " << offset() << ", " << reverseOffset();
+ }
+ theDumper << ")" << std::endl;
+ }
}
//==================================================================================================
const bool theDistancePercent,
const bool theReverse)
{
- // TODO(spo): check that thePart is not empty
std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
-}
+}*/
//==================================================================================================
PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
const ModelHighAPI_Selection& theObject1,
const ModelHighAPI_Selection& theObject2)
{
- // TODO(spo): check that thePart is not empty
std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
-}*/
+}
+
+//==================================================================================================
+PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
+ const ModelHighAPI_Selection& theObject1,
+ const ModelHighAPI_Selection& theObject2,
+ const ModelHighAPI_Double& theDistanceValue,
+ const bool theReverse)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
+ PointPtr anAPI(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
+
+ fillAttribute(ConstructionPlugin_Point::USE_OFFSET(), anAPI->useOffset());
+ fillAttribute(theDistanceValue, anAPI->offset());
+ fillAttribute(theReverse, anAPI->reverseOffset());
+
+ return anAPI;
+}
const ModelHighAPI_Double& theDistanceValue,
const bool theDistancePercent = false,
const bool theReverse = false);
-
- /// Constructor with values.
+ */
+ /// Constructor with values: intersected objects.
CONSTRUCTIONAPI_EXPORT
ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const ModelHighAPI_Selection& theObject1,
- const ModelHighAPI_Selection& theObject2);*/
+ const ModelHighAPI_Selection& theObject2);
/// Destructor.
CONSTRUCTIONAPI_EXPORT
virtual ~ConstructionAPI_Point();
- INTERFACE_3(ConstructionPlugin_Point::ID(),
+ INTERFACE_9(ConstructionPlugin_Point::ID(),
x, ConstructionPlugin_Point::X(), ModelAPI_AttributeDouble, /** X attribute */,
y, ConstructionPlugin_Point::Y(), ModelAPI_AttributeDouble, /** Y attribute */,
- z, ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble, /** Z attribute */)
+ z, ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble, /** Z attribute */,
+ creationMethod, ConstructionPlugin_Point::CREATION_METHOD(),
+ ModelAPI_AttributeString, /** Creation method */,
+ intersectionLine, ConstructionPlugin_Point::INTERSECTION_LINE(),
+ ModelAPI_AttributeSelection, /** Line for intersection */,
+ intersectionPlane, ConstructionPlugin_Point::INTERSECTION_PLANE(),
+ ModelAPI_AttributeSelection, /** Plane for intersection */,
+ useOffset, ConstructionPlugin_Point::USE_OFFSET(),
+ ModelAPI_AttributeString, /** Use offset */,
+ offset, ConstructionPlugin_Point::OFFSET(),
+ ModelAPI_AttributeDouble, /** Offset */,
+ reverseOffset, ConstructionPlugin_Point::REVERSE_OFFSET(),
+ ModelAPI_AttributeBoolean, /** Reverse offset */)
/// Set point values.
CONSTRUCTIONAPI_EXPORT
void setByLinesIntersection(const ModelHighAPI_Selection& theEdge1,
const ModelHighAPI_Selection& theEdge2);
-
+ */
/// Set line and plane for intersections.
CONSTRUCTIONAPI_EXPORT
void setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
- const ModelHighAPI_Selection& theFace);*/
+ const ModelHighAPI_Selection& theFace);
/// Dump wrapped feature
CONSTRUCTIONAPI_EXPORT
const ModelHighAPI_Double& theDistanceValue,
const bool theDistancePercent = false,
const bool theReverse = false);
+*/
+/// \ingroup CPPHighAPI
+/// \brief Create Point feature as an intersection of selected plane (or planar face) and edge
+CONSTRUCTIONAPI_EXPORT
+PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
+ const ModelHighAPI_Selection& theObject1,
+ const ModelHighAPI_Selection& theObject2);
/// \ingroup CPPHighAPI
-/// \brief Create Point feature
+/// \brief Create Point feature as an intersection of selected plane (or planar face) and edge
+/// with positive distance from the plane and flag to reverse the offset direction.
CONSTRUCTIONAPI_EXPORT
PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
const ModelHighAPI_Selection& theObject1,
- const ModelHighAPI_Selection& theObject2);*/
+ const ModelHighAPI_Selection& theObject2,
+ const ModelHighAPI_Double& theDistanceValue,
+ const bool theReverse = false);
#endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_POINT_H_ */
ADD_UNIT_TESTS(TestAxisCreation.py
UnitTestAxis.py
- TestPoint.py
+ TestPoint_XYZ.py
+ TestPoint_LineAndPlane.py
TestPointName.py
TestPlane.py)
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
aFactory->registerValidator("ConstructionPlugin_ValidatorPointLines",
new ConstructionPlugin_ValidatorPointLines());
- aFactory->registerValidator("ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel",
- new ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel());
+ aFactory->registerValidator("ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel",
+ new ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel());
aFactory->registerValidator("ConstructionPlugin_ValidatorPlaneThreePoints",
new ConstructionPlugin_ValidatorPlaneThreePoints());
aFactory->registerValidator("ConstructionPlugin_ValidatorPlaneLinePoint",
#include <ModelAPI_ResultConstruction.h>
#include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAlgoAPI_ShapeTools.h>
#include <GeomAPI_Edge.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Vertex.h>
+#include <GeomAPI_Pln.h>
//==================================================================================================
ConstructionPlugin_Point::ConstructionPlugin_Point()
//==================================================================================================
void ConstructionPlugin_Point::initAttributes()
{
- //data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
-
data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
+
/*data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId());
data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId());
data()->addAttribute(FIRST_LINE(), ModelAPI_AttributeSelection::typeId());
data()->addAttribute(SECOND_LINE(), ModelAPI_AttributeSelection::typeId());
-
+*/
data()->addAttribute(INTERSECTION_LINE(), ModelAPI_AttributeSelection::typeId());
- data()->addAttribute(INTERSECTION_PLANE(), ModelAPI_AttributeSelection::typeId());*/
+ data()->addAttribute(INTERSECTION_PLANE(), ModelAPI_AttributeSelection::typeId());
+
+ data()->addAttribute(USE_OFFSET(), ModelAPI_AttributeString::typeId());
+ data()->addAttribute(OFFSET(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(REVERSE_OFFSET(), ModelAPI_AttributeBoolean::typeId());
}
//==================================================================================================
void ConstructionPlugin_Point::execute()
{
- GeomShapePtr aShape = createByXYZ();
-
- /*GeomShapePtr aShape;
+ GeomShapePtr aShape;
- std::string aCreationMethod = string(CREATION_METHOD())->value();
+ // to support compatibility with old documents where aCreationMethod did not exist
+ std::string aCreationMethod =
+ string(CREATION_METHOD()).get() && !string(CREATION_METHOD())->value().empty() ?
+ string(CREATION_METHOD())->value() : CREATION_METHOD_BY_XYZ();
if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
aShape = createByXYZ();
- } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
+ }/* else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
aShape = createByDistanceOnEdge();
} else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) {
aShape = createByProjection();
} else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) {
aShape = createByLinesIntersection();
- } else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
+ }*/ else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
aShape = createByLineAndPlaneIntersection();
- }*/
+ }
if(!aShape.get()) {
+ setError("Error: intersection not found.");
return;
}
return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge);
}
+*/
//==================================================================================================
std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLineAndPlaneIntersection()
{
// Get line.
- AttributeSelectionPtr aLineSelection= selection(INTERSECTION_LINE());
+ AttributeSelectionPtr aLineSelection = selection(INTERSECTION_LINE());
GeomShapePtr aLineShape = aLineSelection->value();
if(!aLineShape.get()) {
aLineShape = aLineSelection->context()->shape();
}
std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
- return GeomAlgoAPI_PointBuilder::vertexByIntersection(anEdge, aFace);
-}*/
+ if (!string(USE_OFFSET())->value().empty()) {
+ double anOffset = real(OFFSET())->value();
+ if (boolean(REVERSE_OFFSET())->value())
+ anOffset = -anOffset;
+ if (fabs(anOffset) > 1.e-9) { // move face
+ aFace->translate(aFace->getPlane()->direction(), anOffset);
+ }
+ }
+
+ return GeomAlgoAPI_ShapeTools::intersect(anEdge, aFace);
+}
return CONSTRUCTION_POINT_KIND;
}
- /*/// Attribute name for creation method.
+ /// Attribute name for creation method.
inline static const std::string& CREATION_METHOD()
{
static const std::string MY_CREATION_METHOD_ID("creation_method");
static const std::string MY_CREATION_METHOD_ID("by_xyz");
return MY_CREATION_METHOD_ID;
}
-
+ /*
/// Attribute name for creation method.
inline static const std::string& CREATION_METHOD_BY_DISTANCE_ON_EDGE()
{
static const std::string MY_CREATION_METHOD_ID("by_lines_intersection");
return MY_CREATION_METHOD_ID;
}
-
+ */
/// Attribute name for creation method.
inline static const std::string& CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()
{
static const std::string MY_CREATION_METHOD_ID("by_line_and_plane_intersection");
return MY_CREATION_METHOD_ID;
- }*/
+ }
/// Attribute name for X coordinate.
inline static const std::string& X()
static const std::string ATTR_ID("second_line");
return ATTR_ID;
}
+ */
/// Attribute name for selected intersection line.
inline static const std::string& INTERSECTION_LINE()
{
static const std::string ATTR_ID("intersection_plane");
return ATTR_ID;
- }*/
+ }
+
+ /// Attribute name for use offset for the intersection plane.
+ inline static const std::string& USE_OFFSET()
+ {
+ static const std::string ATTR_ID("use_offset");
+ return ATTR_ID;
+ }
+
+ /// Attribute name for offset for the intersection plane.
+ inline static const std::string& OFFSET()
+ {
+ static const std::string ATTR_ID("offset");
+ return ATTR_ID;
+ }
+
+ /// Attribute name for reverse offset for the intersection plane.
+ inline static const std::string& REVERSE_OFFSET()
+ {
+ static const std::string ATTR_ID("reverse_offset");
+ 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> createByLinesIntersection();
- std::shared_ptr<GeomAPI_Vertex> createByLineAndPlaneIntersection();*/
+ std::shared_ptr<GeomAPI_Vertex> createByLinesIntersection();*/
+ std::shared_ptr<GeomAPI_Vertex> createByLineAndPlaneIntersection();
};
#include <GeomAPI_Lin.h>
#include <GeomAPI_Pln.h>
#include <GeomAPI_Vertex.h>
+#include <GeomAlgoAPI_ShapeTools.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeBoolean.h>
#include <Events_InfoMessage.h>
+static std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape);
static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
static std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape);
}
//==================================================================================================
-bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid(
+bool ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel::isValid(
const AttributePtr& theAttribute,
const std::list<std::string>& theArguments,
Events_InfoMessage& theError) const
std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
- std::shared_ptr<GeomAPI_Lin> aLin;
+ std::shared_ptr<GeomAPI_Edge> anEdge;
std::shared_ptr<GeomAPI_Pln> aPln;
GeomShapePtr aShape1 = anAttribute1->value();
aShape2 = aContext2->shape();
}
- aLin = getLin(aShape1);
+ bool isPlaneFirst = false;
+ anEdge = getEdge(aShape1);
aPln = getPln(aShape2);
- if(!aLin.get() || !aPln.get()) {
- aLin = getLin(aShape2);
+ if(!anEdge.get() || !aPln.get()) {
+ anEdge = getEdge(aShape2);
aPln = getPln(aShape1);
+ isPlaneFirst = true;
}
- if(!aLin.get() || !aPln.get()) {
+ if(!anEdge.get() || !aPln.get()) {
theError = "Wrong shape types selected.";
return false;
}
- if(aPln->isParallel(aLin)) {
- theError = "Plane and line are parallel.";
+ std::shared_ptr<GeomAPI_Face> aPlaneFace(new GeomAPI_Face(isPlaneFirst ? aShape1 : aShape2));
+ if(GeomAlgoAPI_ShapeTools::isParallel(anEdge, aPlaneFace)) {
+ theError = "Plane and edge are parallel.";
return false;
}
return true;
}
+std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape)
+{
+ if(!theShape->isEdge()) {
+ return std::shared_ptr<GeomAPI_Edge>();
+ }
+
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
+
+ return anEdge;
+}
+
std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
{
std::shared_ptr<GeomAPI_Lin> aLin;
Events_InfoMessage& theError) const;
};
-/// \class ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel
+/// \class ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel
/// \ingroup Validators
-/// \brief A validator for selection line and plane for point by intersection.
-class ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel: public ModelAPI_AttributeValidator
+/// \brief A validator for selection edge and plane for point by intersection.
+class ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel: public ModelAPI_AttributeValidator
{
public:
//! \return True if the attribute is valid.
aPointFeatureData.real("x").setValue(0.)
aPointFeatureData.real("y").setValue(0.)
aPointFeatureData.real("z").setValue(0.)
+aPointFeatureData.string("creation_method").setValue("by_xyz")
aPointFeature.execute()
aSession.finishOperation()
aPoint1Result = aPointFeature.firstResult();
aPointFeatureData.real("x").setValue(0.)
aPointFeatureData.real("y").setValue(0.)
aPointFeatureData.real("z").setValue(100.)
+aPointFeatureData.string("creation_method").setValue("by_xyz")
aPointFeature.execute()
aSession.finishOperation()
aPoint2Result = aPointFeature.firstResult();
+++ /dev/null
-## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
-##
-## This library is free software; you can redistribute it and/or
-## modify it under the terms of the GNU Lesser General Public
-## License as published by the Free Software Foundation; either
-## version 2.1 of the License, or (at your option) any later version.
-##
-## This library is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-## Lesser General Public License for more details.
-##
-## You should have received a copy of the GNU Lesser General Public
-## License along with this library; if not, write to the Free Software
-## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-##
-## See http:##www.salome-platform.org/ or
-## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
-##
-
-"""
-Test case for Construction Point feature. Written on High API.
-"""
-from ModelAPI import *
-from GeomAPI import *
-
-from salome.shaper import model
-
-# Get session
-aSession = ModelAPI_Session.get()
-
-# Create a part
-aDocument = aSession.activeDocument()
-aSession.startOperation()
-model.addPart(aDocument)
-aDocument = aSession.activeDocument()
-aSession.finishOperation()
-
-# Create a point by coordinates
-aSession.startOperation()
-aPoint = model.addPoint(aDocument, 50, 50, 50)
-aSession.finishOperation()
-assert (len(aPoint.results()) > 0)
-
-# # Create a sketch with lines
-# aSession.startOperation()
-# anOrigin = GeomAPI_Pnt(0, 0, 0)
-# aDirX = GeomAPI_Dir(1, 0, 0)
-# aNorm = GeomAPI_Dir(0, 0, 1)
-# aSketch = model.addSketch(aDocument, GeomAPI_Ax3(anOrigin, aDirX, aNorm))
-# aSketchLine1 = aSketch.addLine(0, 0, 100, 100)
-# aSketchLine2 = aSketch.addLine(0, 100, 100, 0)
-# aSession.finishOperation()
-#
-# # Create a point on line
-# aSession.startOperation()
-# aPoint = model.addPoint(aDocument, aSketchLine1.result()[0], 25, True, False)
-# aSession.finishOperation()
-# assert (len(aPoint.result()) > 0)
-#
-# # Create plane
-# aSession.startOperation()
-# aPlane = model.addPlane(aDocument, 1, 1, 1, 1)
-# aSession.finishOperation()
-#
-# # Create a point by projection
-# aSession.startOperation()
-# aPoint = model.addPoint(aDocument, aPoint.result()[0], aPlane.result()[0])
-# aSession.finishOperation()
-# assert (len(aPoint.result()) > 0)
-#
-# # Create a point by lines intersection
-# aSession.startOperation()
-# aPoint = model.addPoint(aDocument, aSketchLine1.result()[0], aSketchLine2.result()[0])
-# aSession.finishOperation()
-# assert (len(aPoint.result()) > 0)
-#
-# # Create a point by line and plane intersection
-# aSession.startOperation()
-# aPoint = model.addPoint(aDocument, aSketchLine1.result()[0], aPlane.result()[0])
-# aSession.finishOperation()
-# assert (len(aPoint.result()) > 0)
-
-assert(model.checkPythonDump())
aFeatureData.real("x").setValue(0.)
aFeatureData.real("y").setValue(0.)
aFeatureData.real("z").setValue(0.)
+aFeatureData.string("creation_method").setValue("by_xyz")
aFeatureName = aFeature.name()
aFeature.execute()
aSession.finishOperation()
--- /dev/null
+## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
+"""
+Test case for Construction Point feature as intersection of line and plane.
+"""
+
+from salome.shaper import model
+from GeomAPI import *
+
+model.begin()
+partSet = model.moduleDocument()
+Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
+SketchPoint_1 = Sketch_1.addPoint(model.selection("VERTEX", "Origin"))
+SketchCircle_1 = Sketch_1.addCircle(0, 0, 60)
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.result(), SketchCircle_1.center())
+model.do()
+Sketch_2 = model.addSketch(partSet, model.defaultPlane("XOZ"))
+SketchLine_1 = Sketch_2.addLine(60, 100, 0, 20)
+SketchArc_1 = Sketch_2.addArc(0, 0, -65.89631323066888, 61.2998850129882, -90, 0, False)
+model.do()
+
+# point by sketch face and a line
+Point_1 = model.addPoint(partSet, model.selection("EDGE", "Sketch_2/Edge-SketchLine_1"), model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f"))
+model.do()
+# check the point position
+rightPosition = GeomAPI_Vertex(-15, 0, 0)
+assert(rightPosition.isEqual(Point_1.results()[0].resultSubShapePair()[0].shape()))
+
+# point by sketch face and an arc, intersection outside of the face, offset is defined
+Point_2 = model.addPoint(partSet, model.selection("EDGE", "Sketch_2/Edge-SketchArc_1"), model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f"), 10, True)
+# check the point position
+rightPosition = GeomAPI_Vertex(-89.442719099991606, 0, -10)
+assert(rightPosition.isEqual(Point_2.results()[0].resultSubShapePair()[0].shape()))
+
+
+model.end()
+assert(model.checkPythonDump())
--- /dev/null
+## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
+"""
+Test case for Construction Point feature by coordinates.
+"""
+from ModelAPI import *
+from GeomAPI import *
+
+from salome.shaper import model
+
+# Get session
+aSession = ModelAPI_Session.get()
+
+# Create a part
+aDocument = aSession.activeDocument()
+aSession.startOperation()
+model.addPart(aDocument)
+aDocument = aSession.activeDocument()
+aSession.finishOperation()
+
+# Create a point by coordinates
+aSession.startOperation()
+aPoint = model.addPoint(aDocument, 50, 50, 50)
+aSession.finishOperation()
+assert (len(aPoint.results()) > 0)
+
+assert(model.checkPythonDump())
-->
<source>
- <doublevalue id="x" label="X " tooltip="X coordinate" default="0"/>
- <doublevalue id="y" label="Y " tooltip="Y coordinate" default="0"/>
- <doublevalue id="z" label="Z " tooltip="Z coordinate" default="0"/>
-
- <!--<toolbox id="creation_method">
+ <toolbox id="creation_method">
<box id="by_xyz"
title="By X, Y, Z"
tooltip="Point at a given distance from the origin."
icon="icons/Construction/z_size.png"
default="0"/>
</box>
+<!--
<box id="by_distance_on_edge"
title="By distance on edge"
tooltip="Point on an edge, at a given distance of one of its end."
<validator id="ConstructionPlugin_ValidatorPointLines" parameters="first_line"/>
</shape_selector>
</box>
+-->
<box id="by_line_and_plane_intersection"
title="By line and plane intersection"
tooltip="Point by intersection of line and plane."
tooltip="Line for intersection."
icon="icons/Construction/edge.png"
shape_types="edge">
- <validator id="GeomValidators_ShapeType" parameters="line"/>
- <validator id="ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel" parameters="intersection_plane"/>
+ <validator id="ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel" parameters="intersection_plane"/>
</shape_selector>
<shape_selector id="intersection_plane"
label="Plane"
icon="icons/Construction/face.png"
shape_types="face">
<validator id="GeomValidators_Face" parameters="plane"/>
- <validator id="ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel" parameters="intersection_line"/>
+ <validator id="ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel" parameters="intersection_line"/>
</shape_selector>
+ <optionalbox id="use_offset" title="Offset from the plane">
+ <doublevalue id="offset" label="Distance " tooltip="Distance from the plane" min="0" default="0"/>
+ <boolvalue id="reverse_offset" label="Reverse" tooltip="Reverse offset value" default="false"/>
+ </optionalbox>
</box>
- </toolbox>-->
+ </toolbox>
</source>
aMyPln.Axis().IsParallel(anOtherPln.Axis(), theTolerance));
}
-bool GeomAPI_Pln::isParallel(const std::shared_ptr<GeomAPI_Lin> theLine)
-{
- std::shared_ptr<GeomAPI_XYZ> aLineDir = theLine->direction()->xyz();
- std::shared_ptr<GeomAPI_XYZ> aLineLoc = theLine->location()->xyz();
-
- std::shared_ptr<GeomAPI_XYZ> aNormal = direction()->xyz();
- std::shared_ptr<GeomAPI_XYZ> aLocation = location()->xyz();
-
- double aDot = aNormal->dot(aLineDir);
- return Abs(aDot) < Precision::SquareConfusion();
-}
-
std::shared_ptr<GeomAPI_Pnt>
GeomAPI_Pln::intersect(const std::shared_ptr<GeomAPI_Lin>& theLine) const
{
GEOMAPI_EXPORT
bool isCoincident(const std::shared_ptr<GeomAPI_Pln> thePlane, const double theTolerance = 1.e-7);
- /// Returns true if plane is parallel to theLine.
- GEOMAPI_EXPORT
- bool isParallel(const std::shared_ptr<GeomAPI_Lin> theLine);
-
/// Returns intersection point or empty if no intersections
GEOMAPI_EXPORT
std::shared_ptr<GeomAPI_Pnt> intersect(const std::shared_ptr<GeomAPI_Lin>& theLine) const;
return false;
}
+
+void GeomAPI_Shape::translate(const std::shared_ptr<GeomAPI_Dir> theDir, const double theOffset)
+{
+ gp_Dir aDir = theDir->impl<gp_Dir>();
+ gp_Vec aTrsfVec(aDir.XYZ() * theOffset);
+ gp_Trsf aTranslation;
+ aTranslation.SetTranslation(aTrsfVec);
+ TopoDS_Shape aResult = MY_SHAPE->Moved(aTranslation);
+ setImpl(new TopoDS_Shape(aResult));
+}
#ifndef GeomAPI_Shape_H_
#define GeomAPI_Shape_H_
+#include "GeomAPI_Dir.h"
+
#include <GeomAPI_Interface.h>
#include <memory>
#include <list>
/// Returns true if min distance between shapes < tolerance.
GEOMAPI_EXPORT
bool isIntersect(const std::shared_ptr<GeomAPI_Shape> theShape) const;
+
+ // Translates the shape along the direction for the given offset
+ GEOMAPI_EXPORT
+ void translate(const std::shared_ptr<GeomAPI_Dir> theDir, const double theOffset);
};
//! Pointer on list of shapes
#include <BRepGProp.hxx>
#include <BRepTools.hxx>
#include <BRepTopAdaptor_FClass2d.hxx>
+#include <BRepClass_FaceClassifier.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom2d_Curve.hxx>
#include <BRepLib_CheckCurveOnSurface.hxx>
#include <Geom_Plane.hxx>
#include <GeomLib_IsPlanarSurface.hxx>
#include <GeomLib_Tool.hxx>
+#include <GeomAPI_ExtremaCurveSurface.hxx>
#include <gp_Pln.hxx>
#include <GProp_GProps.hxx>
#include <IntAna_IntConicQuad.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
+
#include <BOPAlgo_Builder.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <TopoDS_Edge.hxx>
return anExt.IsParallel() == Standard_True;
}
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_ShapeTools::intersect(
+ const std::shared_ptr<GeomAPI_Edge> theEdge, const std::shared_ptr<GeomAPI_Face> theFace)
+{
+ if(!theEdge.get() || !theFace.get()) {
+ return false;
+ }
+
+ TopoDS_Edge anEdge = TopoDS::Edge(theEdge->impl<TopoDS_Shape>());
+ double aFirstOnCurve, aLastOnCurve;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirstOnCurve, aLastOnCurve);
+
+ TopoDS_Face aFace = TopoDS::Face(theFace->impl<TopoDS_Shape>());
+ Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
+
+ GeomAPI_ExtremaCurveSurface anExt(aCurve, aSurf);
+ // searching for the best point-intersection
+ int aMaxLevel = 0;
+ gp_Pnt aResult;
+ for(int anIntNum = 1; anIntNum <= anExt.NbExtrema(); anIntNum++) {
+ if (anExt.Distance(anIntNum) > Precision::Confusion())
+ continue;
+ Standard_Real aW, aU, aV;
+ anExt.Parameters(anIntNum, aW, aU, aV);
+ gp_Pnt2d aPointOfSurf(aU, aV);
+ // level of the intersection: if it is inside of edge and/or face the level is higher
+ int aIntLevel = aW > aFirstOnCurve && aW < aLastOnCurve ? 2 : 1;
+ BRepClass_FaceClassifier aFClass(aFace, aPointOfSurf, Precision::Confusion());
+ if (aFClass.State() == TopAbs_IN) // "in" is better than "on"
+ aIntLevel += 2;
+ else if (aFClass.State() == TopAbs_ON)
+ aIntLevel += 1;
+ if (aMaxLevel < aIntLevel) {
+ aMaxLevel = anIntNum;
+ anExt.Points(anIntNum, aResult, aResult);
+ }
+ }
+ if (aMaxLevel > 0) { // intersection found
+ return std::shared_ptr<GeomAPI_Vertex>(
+ new GeomAPI_Vertex(aResult.X(), aResult.Y(), aResult.Z()));
+ }
+ return std::shared_ptr<GeomAPI_Vertex>(); // no intersection found
+}
+
//==================================================================================================
void GeomAlgoAPI_ShapeTools::splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
const GeomAlgoAPI_ShapeTools::PointToRefsMap& thePointsInfo,
GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
const std::shared_ptr<GeomAPI_Face> theFace);
+ // Computes intersection point between the edge curve and a face surface (only one point, with
+ // preferences to point that belongs to edge and face boundaries.
+ /// \returns null if there is no intersection
+ GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Vertex> intersect(
+ const std::shared_ptr<GeomAPI_Edge> theEdge, const std::shared_ptr<GeomAPI_Face> theFace);
+
typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
aPoint->real("x")->setValue(theX);
aPoint->real("y")->setValue(theY);
aPoint->real("z")->setValue(theZ);
+ aPoint->string("creation_method")->setValue("by_xyz");
aPoint->data()->setName(theName);
// don't show automatically created feature in the features history
aPoint->setInHistory(aPoint, false);
aFeature.real("x").setValue(1.)
aFeature.real("y").setValue(-1.)
aFeature.real("z").setValue(0.)
+aFeature.string("creation_method").setValue("by_xyz")
aFeatureName = aFeature.name()
# "2" is because Origin is the first point
assert(aFeatureName == "Point_2")
aFeature.real("x").setValue(0.)
aFeature.real("y").setValue(0.)
aFeature.real("z").setValue(0.)
+aFeature.string("creation_method").setValue("by_xyz")
anOriginName = aFeature.name()
aSession.finishOperation()
#=========================================================================
aFeature.real("x").setValue(0.)
aFeature.real("y").setValue(0.)
aFeature.real("z").setValue(0.)
+aFeature.string("creation_method").setValue("by_xyz")
anOriginName = aFeature.name()
aSession.finishOperation()
#=========================================================================