From: dbv Date: Thu, 28 Jun 2018 20:57:36 +0000 (+0300) Subject: 2.3.4 Point creation: by intersection X-Git-Tag: SHAPER_V9_1_0RC1~149 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e9bc8b0ef4a083909ae41172e6ac891136051c91;p=modules%2Fshaper.git 2.3.4 Point creation: by intersection --- diff --git a/src/ConstructionAPI/ConstructionAPI_Point.cpp b/src/ConstructionAPI/ConstructionAPI_Point.cpp index fd6d468ec..e5925482f 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Point.cpp @@ -73,16 +73,37 @@ ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theObject1, + const ModelHighAPI_Selection& theObject2, + const ModelHighAPI_Selection& theObject3) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) + { + GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1); + GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2); + GeomAPI_Shape::ShapeType aType3 = getShapeType(theObject3); + if (aType1 == GeomAPI_Shape::FACE + && aType2 == GeomAPI_Shape::FACE + && aType3 == GeomAPI_Shape::FACE) + { + setByPlanesIntersection(theObject1, theObject2, theObject3); + } + } +} + //================================================================================================== ConstructionAPI_Point::~ConstructionAPI_Point() { @@ -152,37 +173,53 @@ void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection& execute(); } -/* //================================================================================================== void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection& theEdge1, const ModelHighAPI_Selection& theEdge2) { - fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINES_INTERSECTION(), mycreationMethod); - fillAttribute(theEdge1, myfirstLine); - fillAttribute(theEdge2, mysecondLine); + fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod); + fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES(), + myintersectionType); + fillAttribute(theEdge1, myintersectionLine1); + fillAttribute(theEdge2, myintersectionLine2); 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_INTERSECTION(), mycreationMethod); + fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINE_AND_PLANE(), + myintersectionType); fillAttribute(theEdge, myintersectionLine); fillAttribute(theFace, myintersectionPlane); fillAttribute("", useOffset()); // not used by default execute(); } +//================================================================================================== +void ConstructionAPI_Point::setByPlanesIntersection(const ModelHighAPI_Selection& theFace1, + const ModelHighAPI_Selection& theFace2, + const ModelHighAPI_Selection& theFace3) +{ + fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION(), mycreationMethod); + fillAttribute(ConstructionPlugin_Point::INTERSECTION_TYPE_BY_PLANES(), + myintersectionType); + fillAttribute(theFace1, myintersectionPlane1); + fillAttribute(theFace2, myintersectionPlane2); + fillAttribute(theFace3, myintersectionPlane3); + + execute(); +} + //================================================================================================== void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const { FeaturePtr aBase = feature(); const std::string& aDocName = theDumper.name(aBase->document()); - const std::string& aMeth = creationMethod()->value(); + const std::string aMeth = creationMethod()->value(); // common part theDumper << aBase << " = model.addPoint(" << aDocName << ", "; @@ -190,10 +227,24 @@ void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const if (aMeth == "" || // default is XYZ aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) { theDumper << x() << ", " << y() << ", " << z(); - } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) { - theDumper << intersectionLine() << ", " <value().empty()) { // call method with defined offset - theDumper << ", " << offset() << ", " << reverseOffset(); + } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION()) { + const std::string anIntersectionType = intersectionType()->value(); + if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES()) + { + theDumper << intersectionLine1() << ", " << intersectionLine2(); + } + else if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINE_AND_PLANE()) + { + theDumper << intersectionLine() << ", " << intersectionPlane(); + if (!useOffset()->value().empty()) { // call method with defined offset + theDumper << ", " << offset() << ", " << reverseOffset(); + } + } + else if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_PLANES()) + { + theDumper << intersectionPlane1() << ", " + << intersectionPlane2() << ", " + << intersectionPlane3(); } } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE()) { theDumper << edge() << ", "; @@ -262,3 +313,13 @@ PointPtr addPoint(const std::shared_ptr & thePart, return anAPI; } + +//================================================================================================== +PointPtr addPoint(const std::shared_ptr & thePart, + const ModelHighAPI_Selection& theObject1, + const ModelHighAPI_Selection& theObject2, + const ModelHighAPI_Selection& theObject3) +{ + std::shared_ptr aFeature = thePart->addFeature(ConstructionAPI_Point::ID()); + return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2, theObject3)); +} diff --git a/src/ConstructionAPI/ConstructionAPI_Point.h b/src/ConstructionAPI/ConstructionAPI_Point.h index a6145dc47..247a5c22b 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.h +++ b/src/ConstructionAPI/ConstructionAPI_Point.h @@ -63,20 +63,39 @@ public: const ModelHighAPI_Selection& theObject1, const ModelHighAPI_Selection& theObject2); + /// Constructor with values: intersected objects. + CONSTRUCTIONAPI_EXPORT + ConstructionAPI_Point(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theObject1, + const ModelHighAPI_Selection& theObject2, + const ModelHighAPI_Selection& theObject3); + /// Destructor. CONSTRUCTIONAPI_EXPORT virtual ~ConstructionAPI_Point(); - INTERFACE_18(ConstructionPlugin_Point::ID(), + INTERFACE_24(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 */, creationMethod, ConstructionPlugin_Point::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */, + intersectionType, ConstructionPlugin_Point::INTERSECTION_TYPE(), + ModelAPI_AttributeString, /** Type of the intersection */, + intersectionLine1, ConstructionPlugin_Point::INTERSECTION_LINE_1(), + ModelAPI_AttributeSelection, /** Line for intersection */, + intersectionLine2, ConstructionPlugin_Point::INTERSECTION_LINE_2(), + ModelAPI_AttributeSelection, /** Line for intersection */, intersectionLine, ConstructionPlugin_Point::INTERSECTION_LINE(), ModelAPI_AttributeSelection, /** Line for intersection */, intersectionPlane, ConstructionPlugin_Point::INTERSECTION_PLANE(), ModelAPI_AttributeSelection, /** Plane for intersection */, + intersectionPlane1, ConstructionPlugin_Point::INTERSECTION_PLANE_1(), + ModelAPI_AttributeSelection, /** Plane for intersection */, + intersectionPlane2, ConstructionPlugin_Point::INTERSECTION_PLANE_2(), + ModelAPI_AttributeSelection, /** Plane for intersection */, + intersectionPlane3, ConstructionPlugin_Point::INTERSECTION_PLANE_3(), + ModelAPI_AttributeSelection, /** Plane for intersection */, useOffset, ConstructionPlugin_Point::USE_OFFSET(), ModelAPI_AttributeString, /** Use offset */, offset, ConstructionPlugin_Point::OFFSET(), @@ -126,18 +145,22 @@ public: void setByProjectionOnFace(const ModelHighAPI_Selection& theVertex, const ModelHighAPI_Selection& theFace); - /* /// Set lines for intersections. 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); + /// Set faces for intersections. + CONSTRUCTIONAPI_EXPORT + void setByPlanesIntersection(const ModelHighAPI_Selection& theFace1, + const ModelHighAPI_Selection& theFace2, + const ModelHighAPI_Selection& theFace3); + /// Dump wrapped feature CONSTRUCTIONAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const; @@ -180,4 +203,12 @@ PointPtr addPoint(const std::shared_ptr & thePart, const ModelHighAPI_Double& theDistanceValue, const bool theReverse = false); +/// \ingroup CPPHighAPI +/// \brief Create Point feature as an intersection of selected planes +CONSTRUCTIONAPI_EXPORT +PointPtr addPoint(const std::shared_ptr & thePart, + const ModelHighAPI_Selection& theObject1, + const ModelHighAPI_Selection& theObject2, + const ModelHighAPI_Selection& theObject3); + #endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_POINT_H_ */ diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index e9c42f299..919c7dcf2 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -78,7 +78,9 @@ INCLUDE_DIRECTORIES( ADD_UNIT_TESTS(TestAxisCreation.py UnitTestAxis.py TestPoint_XYZ.py - TestPoint_LineAndPlane.py + TestPoint_IntersectLines.py + TestPoint_IntersectLineAndPlane.py + TestPoint_IntersectPlanes.py TestPoint_Edge.py TestPoint_ProjectOnEdge.py TestPoint_ProjectOnFace.py diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index a9f231b82..3eaecc591 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -52,6 +52,8 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin() new ConstructionPlugin_ValidatorPlaneTwoParallelPlanes()); aFactory->registerValidator("ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes", new ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes()); + aFactory->registerValidator("ConstructionPlugin_ValidatorPointThreeNonParallelPlanes", + new ConstructionPlugin_ValidatorPointThreeNonParallelPlanes()); Config_PropManager::registerProp(SKETCH_TAB_NAME, "planes_size", "Size", Config_Prop::DblSpin, PLANE_SIZE); diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index 400824b7d..e6ee010c2 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -55,14 +55,11 @@ void ConstructionPlugin_Point::initAttributes() data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId()); -/* - data()->addAttribute(FIRST_LINE(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(SECOND_LINE(), ModelAPI_AttributeSelection::typeId()); -*/ + data()->addAttribute(INTERSECTION_LINE_1(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(INTERSECTION_LINE_2(), ModelAPI_AttributeSelection::typeId()); data()->addAttribute(INTERSECTION_LINE(), 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()); @@ -77,6 +74,12 @@ void ConstructionPlugin_Point::initAttributes() data()->addAttribute(PROJECTION_TYPE(), ModelAPI_AttributeString::typeId()); data()->addAttribute(EDGE_FOR_POINT_PROJECTION(), ModelAPI_AttributeSelection::typeId()); data()->addAttribute(FACE_FOR_POINT_PROJECTION(), ModelAPI_AttributeSelection::typeId()); + + data()->addAttribute(INTERSECTION_TYPE(), ModelAPI_AttributeString::typeId()); + + data()->addAttribute(INTERSECTION_PLANE_1(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(INTERSECTION_PLANE_2(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(INTERSECTION_PLANE_3(), ModelAPI_AttributeSelection::typeId()); } //================================================================================================== @@ -98,22 +101,27 @@ void ConstructionPlugin_Point::execute() } else { aShape = createByProjectionOnFace(); } - } /* else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) { - aShape = createByLinesIntersection(); - } */ else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) { - // this may produce several points - std::list > aPoints = createByLineAndPlaneIntersection(); - if (!aPoints.empty()) { // if no points found produce the standard error later - int anIndex = 0; - std::list >::iterator aPIter = aPoints.begin(); - for(; aPIter != aPoints.end(); aPIter++, anIndex++) { - std::shared_ptr aConstr = - document()->createConstruction(data(), anIndex); - aConstr->setShape(*aPIter); - setResult(aConstr, anIndex); + } else if(aCreationMethod == CREATION_METHOD_BY_INTERSECTION()) { + std::string anIntersectionType = string(INTERSECTION_TYPE())->value(); + if (anIntersectionType == INTERSECTION_TYPE_BY_LINES()) { + aShape = createByLinesIntersection(); + } else if (anIntersectionType == INTERSECTION_TYPE_BY_LINE_AND_PLANE()) { + // this may produce several points + std::list > aPoints = createByLineAndPlaneIntersection(); + if (!aPoints.empty()) { // if no points found produce the standard error later + int anIndex = 0; + std::list >::iterator aPIter = aPoints.begin(); + for (; aPIter != aPoints.end(); aPIter++, anIndex++) { + std::shared_ptr aConstr = + document()->createConstruction(data(), anIndex); + aConstr->setShape(*aPIter); + setResult(aConstr, anIndex); + } + removeResults(anIndex); + return; } - removeResults(anIndex); - return; + } else { + aShape = createByPlanesIntersection(); } } @@ -219,12 +227,11 @@ std::shared_ptr ConstructionPlugin_Point::createByProjectionOnFa return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace); } -/* //================================================================================================== std::shared_ptr ConstructionPlugin_Point::createByLinesIntersection() { // Get first line. - AttributeSelectionPtr aFirstLineSelection= selection(FIRST_LINE()); + AttributeSelectionPtr aFirstLineSelection= selection(INTERSECTION_LINE_1()); GeomShapePtr aFirstLineShape = aFirstLineSelection->value(); if(!aFirstLineShape.get()) { aFirstLineShape = aFirstLineSelection->context()->shape(); @@ -232,7 +239,7 @@ std::shared_ptr ConstructionPlugin_Point::createByLinesIntersect std::shared_ptr aFirstEdge(new GeomAPI_Edge(aFirstLineShape)); // Get second line. - AttributeSelectionPtr aSecondLineSelection= selection(SECOND_LINE()); + AttributeSelectionPtr aSecondLineSelection= selection(INTERSECTION_LINE_2()); GeomShapePtr aSecondLineShape = aSecondLineSelection->value(); if(!aSecondLineShape.get()) { aSecondLineShape = aSecondLineSelection->context()->shape(); @@ -241,7 +248,6 @@ std::shared_ptr ConstructionPlugin_Point::createByLinesIntersect return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge); } -*/ //================================================================================================== std::list > @@ -275,3 +281,48 @@ std::list > return GeomAlgoAPI_ShapeTools::intersect(anEdge, aFace, aPlaneSelection->context()->groupName() == ModelAPI_ResultConstruction::group()); } + +//================================================================================================== +std::shared_ptr ConstructionPlugin_Point::createByPlanesIntersection() +{ + // Get plane. + AttributeSelectionPtr aPlaneSelection1 = selection(INTERSECTION_PLANE_1()); + GeomShapePtr aPlaneShape1 = aPlaneSelection1->value(); + if (!aPlaneShape1.get()) { + aPlaneShape1 = aPlaneSelection1->context()->shape(); + } + std::shared_ptr aFace1(new GeomAPI_Face(aPlaneShape1)); + std::shared_ptr aPln1 = aFace1->getPlane(); + + // Get plane. + AttributeSelectionPtr aPlaneSelection2 = selection(INTERSECTION_PLANE_2()); + GeomShapePtr aPlaneShape2 = aPlaneSelection2->value(); + if (!aPlaneShape2.get()) { + aPlaneShape2 = aPlaneSelection2->context()->shape(); + } + std::shared_ptr aFace2(new GeomAPI_Face(aPlaneShape2)); + std::shared_ptr aPln2 = aFace2->getPlane(); + + // Get plane. + AttributeSelectionPtr aPlaneSelection3 = selection(INTERSECTION_PLANE_3()); + GeomShapePtr aPlaneShape3 = aPlaneSelection3->value(); + if (!aPlaneShape3.get()) { + aPlaneShape3 = aPlaneSelection3->context()->shape(); + } + std::shared_ptr aFace3(new GeomAPI_Face(aPlaneShape3)); + std::shared_ptr aPln3 = aFace3->getPlane(); + + std::shared_ptr aVertex; + + std::shared_ptr anIntersectLine = aPln1->intersect(aPln2); + if (!anIntersectLine.get()) { + return aVertex; + } + + std::shared_ptr aPnt = aPln3->intersect(anIntersectLine); + if (aPnt.get()) { + aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z())); + } + + return aVertex; +} diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.h b/src/ConstructionPlugin/ConstructionPlugin_Point.h index 0f4103b49..49db67df9 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.h @@ -75,19 +75,10 @@ public: return MY_CREATION_METHOD_ID; } - /* /// Attribute name for creation method. - inline static const std::string& CREATION_METHOD_BY_LINES_INTERSECTION() + inline static const std::string& CREATION_METHOD_BY_INTERSECTION() { - 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"); + static const std::string MY_CREATION_METHOD_ID("by_intersection"); return MY_CREATION_METHOD_ID; } @@ -203,21 +194,47 @@ public: return ATTR_ID; } - /* - /// Attribute name for selected first line. - inline static const std::string& FIRST_LINE() + /// Attribute name for intersection type. + inline static const std::string& INTERSECTION_TYPE() { - static const std::string ATTR_ID("first_line"); + static const std::string ATTR_ID("intersection_type"); return ATTR_ID; } - /// Attribute name for selected second line. - inline static const std::string& SECOND_LINE() + /// Attribute name for intersection type by lines. + inline static const std::string& INTERSECTION_TYPE_BY_LINES() { - static const std::string ATTR_ID("second_line"); + static const std::string MY_CREATION_METHOD_ID("intersection_type_by_lines"); + return MY_CREATION_METHOD_ID; + } + + /// Attribute name for intersection type by line and plane. + inline static const std::string& INTERSECTION_TYPE_BY_LINE_AND_PLANE() + { + static const std::string MY_CREATION_METHOD_ID("intersection_type_by_line_and_plane"); + return MY_CREATION_METHOD_ID; + } + + /// Attribute name for intersection type by planes. + inline static const std::string& INTERSECTION_TYPE_BY_PLANES() + { + static const std::string MY_CREATION_METHOD_ID("intersection_type_by_planes"); + return MY_CREATION_METHOD_ID; + } + + /// Attribute name for selected first intersection line. + inline static const std::string& INTERSECTION_LINE_1() + { + static const std::string ATTR_ID("intersection_line_1"); + return ATTR_ID; + } + + /// Attribute name for selected second intersection line. + inline static const std::string& INTERSECTION_LINE_2() + { + static const std::string ATTR_ID("intersection_line_2"); return ATTR_ID; } - */ /// Attribute name for selected intersection line. inline static const std::string& INTERSECTION_LINE() @@ -254,6 +271,27 @@ public: return ATTR_ID; } + /// Attribute name for selected intersection plane. + inline static const std::string& INTERSECTION_PLANE_1() + { + static const std::string ATTR_ID("intersection_plane_1"); + return ATTR_ID; + } + + /// Attribute name for selected intersection plane. + inline static const std::string& INTERSECTION_PLANE_2() + { + static const std::string ATTR_ID("intersection_plane_2"); + return ATTR_ID; + } + + /// Attribute name for selected intersection plane. + inline static const std::string& INTERSECTION_PLANE_3() + { + static const std::string ATTR_ID("intersection_plane_3"); + return ATTR_ID; + } + /// Creates a new part document if needed. CONSTRUCTIONPLUGIN_EXPORT virtual void execute(); @@ -275,9 +313,9 @@ private: std::shared_ptr createByDistanceOnEdge(); std::shared_ptr createByProjectionOnEdge(); std::shared_ptr createByProjectionOnFace(); - /*std::shared_ptr createByLinesIntersection();*/ + std::shared_ptr createByLinesIntersection(); std::list > createByLineAndPlaneIntersection(); - + std::shared_ptr createByPlanesIntersection(); }; #endif diff --git a/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp b/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp index 146e3055a..2390b83a4 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp @@ -83,6 +83,11 @@ bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttr std::shared_ptr aLine1 = aLineEdge1->line(); std::shared_ptr aLine2 = aLineEdge2->line(); + if (!aLine1.get() || !aLine2.get()) { + theError = "Selected edge is not a line."; + return false; + } + if(!aLine1->isCoplanar(aLine2)) { theError = "Selected lines not coplanar."; return false; @@ -392,6 +397,81 @@ bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid( return true; } +//================================================================================================== +bool ConstructionPlugin_ValidatorPointThreeNonParallelPlanes::isValid( + const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); + + AttributeSelectionPtr anAttribute1 = + std::dynamic_pointer_cast(theAttribute); + AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front()); + AttributeSelectionPtr anAttribute3 = aFeature->selection(theArguments.back()); + + GeomShapePtr aShape1 = anAttribute1->value(); + ResultPtr aContext1 = anAttribute1->context(); + if (!aContext1.get()) { + theError = "One of the attribute not initialized."; + return false; + } + if (!aShape1.get()) { + aShape1 = aContext1->shape(); + } + + std::shared_ptr aPln1 = getPln(aShape1); + if (!aPln1.get()) { + theError = "Wrong shape types selected."; + return false; + } + std::shared_ptr aDir1 = aPln1->direction(); + + if (anAttribute2.get()) { + GeomShapePtr aShape2 = anAttribute2->value(); + ResultPtr aContext2 = anAttribute2->context(); + if (!aShape2.get() && aContext2.get()) { + aShape2 = aContext2->shape(); + } + + if (aShape2.get()) { + std::shared_ptr aPln2 = getPln(aShape2); + if (!aPln2.get()) { + theError = "Wrong shape types selected."; + return false; + } + std::shared_ptr aDir2 = aPln2->direction(); + if (aDir1->isParallel(aDir2)) { + theError = "Planes are parallel."; + return false; + } + } + } + + if (anAttribute3.get()) { + GeomShapePtr aShape3 = anAttribute3->value(); + ResultPtr aContext3 = anAttribute3->context(); + if (!aShape3.get() && aContext3.get()) { + aShape3 = aContext3->shape(); + } + + if (aShape3.get()) { + std::shared_ptr aPln3 = getPln(aShape3); + if (!aPln3.get()) { + theError = "Wrong shape types selected."; + return false; + } + std::shared_ptr aDir3 = aPln3->direction(); + if (aDir1->isParallel(aDir3)) { + theError = "Planes are parallel."; + return false; + } + } + } + + return true; +} + std::shared_ptr getEdge(const GeomShapePtr theShape) { if(!theShape->isEdge()) { diff --git a/src/ConstructionPlugin/ConstructionPlugin_Validators.h b/src/ConstructionPlugin/ConstructionPlugin_Validators.h index 3254672de..e5dbdd289 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Validators.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Validators.h @@ -113,4 +113,19 @@ public: Events_InfoMessage& theError) const; }; +/// \class ConstructionPlugin_ValidatorPointThreeNonParallelPlanes +/// \ingroup Validators +/// \brief A validator for selection three non parallel planes. +class ConstructionPlugin_ValidatorPointThreeNonParallelPlanes: 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& theArguments, + Events_InfoMessage& theError) const; +}; + #endif \ No newline at end of file diff --git a/src/ConstructionPlugin/Test/TestPoint_IntersectLineAndPlane.py b/src/ConstructionPlugin/Test/TestPoint_IntersectLineAndPlane.py new file mode 100644 index 000000000..635ab8102 --- /dev/null +++ b/src/ConstructionPlugin/Test/TestPoint_IntersectLineAndPlane.py @@ -0,0 +1,55 @@ +## 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 +## + +""" +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()) diff --git a/src/ConstructionPlugin/Test/TestPoint_IntersectLines.py b/src/ConstructionPlugin/Test/TestPoint_IntersectLines.py new file mode 100644 index 000000000..f3b08471a --- /dev/null +++ b/src/ConstructionPlugin/Test/TestPoint_IntersectLines.py @@ -0,0 +1,51 @@ +## 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 +## + +""" +Test case for Construction Point feature by lines intersection. +""" + +from salome.shaper import model +from GeomAPI import * + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False) +SketchPoint_1 = SketchProjection_1.createdFeature() +SketchLine_1 = Sketch_1.addLine(-50, 50, 50, 50) +model.do() +Box_1 = model.addBox(Part_1_doc, 25, 100, 100) +Point_2 = model.addPoint(Part_1_doc, model.selection("EDGE", "Box_1_1/Back&Box_1_1/Bottom"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_1")) +Point_3 = model.addPoint(Part_1_doc, model.selection("EDGE", "Sketch_1/Edge-SketchLine_1"), model.selection("EDGE", "Box_1_1/Front&Box_1_1/Bottom")) +model.do() +model.end() + +assert (len(Point_2.results()) > 0) +rightPosition = GeomAPI_Vertex(0, 50, 0) +assert(rightPosition.isEqual(Point_2.results()[0].resultSubShapePair()[0].shape())) + +assert (len(Point_3.results()) > 0) +rightPosition = GeomAPI_Vertex(25, 50, 0) +assert(rightPosition.isEqual(Point_3.results()[0].resultSubShapePair()[0].shape())) + +assert(model.checkPythonDump()) diff --git a/src/ConstructionPlugin/Test/TestPoint_IntersectPlanes.py b/src/ConstructionPlugin/Test/TestPoint_IntersectPlanes.py new file mode 100644 index 000000000..16d89773b --- /dev/null +++ b/src/ConstructionPlugin/Test/TestPoint_IntersectPlanes.py @@ -0,0 +1,50 @@ +## 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 +## + +""" +Test case for Construction Point feature by planes intersection. +""" + +from salome.shaper import model +from GeomAPI import * + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Point_2 = model.addPoint(Part_1_doc, 50, 50, 50) +Plane_4 = model.addPlane(Part_1_doc, model.selection("EDGE", "PartSet/OY"), model.selection("VERTEX", "Point_1"), False) +Plane_5 = model.addPlane(Part_1_doc, model.selection("EDGE", "PartSet/OX"), model.selection("VERTEX", "Point_1"), False) +Plane_6 = model.addPlane(Part_1_doc, model.selection("EDGE", "PartSet/OZ"), model.selection("VERTEX", "Point_1"), True) +Point_3 = model.addPoint(Part_1_doc, model.selection("FACE", "Plane_1"), model.selection("FACE", "Plane_2"), model.selection("FACE", "Plane_3")) +Box_1 = model.addBox(Part_1_doc, 50, 25, 100) +Point_4 = model.addPoint(Part_1_doc, model.selection("FACE", "Plane_1"), model.selection("FACE", "Plane_3"), model.selection("FACE", "Box_1_1/Right")) +model.do() +model.end() + +assert (len(Point_3.results()) > 0) +rightPosition = GeomAPI_Vertex(50, 50, 50) +assert(rightPosition.isEqual(Point_3.results()[0].resultSubShapePair()[0].shape())) + +assert (len(Point_4.results()) > 0) +rightPosition = GeomAPI_Vertex(50, 25, 50) +assert(rightPosition.isEqual(Point_4.results()[0].resultSubShapePair()[0].shape())) + +assert(model.checkPythonDump()) diff --git a/src/ConstructionPlugin/Test/TestPoint_LineAndPlane.py b/src/ConstructionPlugin/Test/TestPoint_LineAndPlane.py deleted file mode 100644 index 635ab8102..000000000 --- a/src/ConstructionPlugin/Test/TestPoint_LineAndPlane.py +++ /dev/null @@ -1,55 +0,0 @@ -## 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 -## - -""" -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()) diff --git a/src/ConstructionPlugin/icons/point_by_intersection_32x32.png b/src/ConstructionPlugin/icons/point_by_intersection_32x32.png new file mode 100644 index 000000000..ae3fb7968 Binary files /dev/null and b/src/ConstructionPlugin/icons/point_by_intersection_32x32.png differ diff --git a/src/ConstructionPlugin/icons/point_by_line_and_plane_intersection_24x24.png b/src/ConstructionPlugin/icons/point_by_line_and_plane_intersection_24x24.png new file mode 100644 index 000000000..1955e2e42 Binary files /dev/null and b/src/ConstructionPlugin/icons/point_by_line_and_plane_intersection_24x24.png differ diff --git a/src/ConstructionPlugin/icons/point_by_lines_intersection_24x24.png b/src/ConstructionPlugin/icons/point_by_lines_intersection_24x24.png new file mode 100644 index 000000000..4a01f7063 Binary files /dev/null and b/src/ConstructionPlugin/icons/point_by_lines_intersection_24x24.png differ diff --git a/src/ConstructionPlugin/icons/point_by_planes_intersection_24x24.png b/src/ConstructionPlugin/icons/point_by_planes_intersection_24x24.png new file mode 100644 index 000000000..6d5966ab7 Binary files /dev/null and b/src/ConstructionPlugin/icons/point_by_planes_intersection_24x24.png differ diff --git a/src/ConstructionPlugin/point_widget.xml b/src/ConstructionPlugin/point_widget.xml index 8fb77b2a7..00b4caf8b 100644 --- a/src/ConstructionPlugin/point_widget.xml +++ b/src/ConstructionPlugin/point_widget.xml @@ -118,53 +118,100 @@ email : webmaster.salome@opencascade.com - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - diff --git a/src/ModelHighAPI/ModelHighAPI_Macro.h b/src/ModelHighAPI/ModelHighAPI_Macro.h index a03e9e72d..13ced7b69 100644 --- a/src/ModelHighAPI/ModelHighAPI_Macro.h +++ b/src/ModelHighAPI/ModelHighAPI_Macro.h @@ -750,5 +750,86 @@ END_INIT() \ public: +//-------------------------------------------------------------------------------------- +#define INTERFACE_24(KIND, \ + N_0, AN_0, T_0, C_0, \ + N_1, AN_1, T_1, C_1, \ + N_2, AN_2, T_2, C_2, \ + N_3, AN_3, T_3, C_3, \ + N_4, AN_4, T_4, C_4, \ + N_5, AN_5, T_5, C_5, \ + N_6, AN_6, T_6, C_6, \ + N_7, AN_7, T_7, C_7, \ + N_8, AN_8, T_8, C_8, \ + N_9, AN_9, T_9, C_9, \ + N_10, AN_10, T_10, C_10, \ + N_11, AN_11, T_11, C_11, \ + N_12, AN_12, T_12, C_12, \ + N_13, AN_13, T_13, C_13, \ + N_14, AN_14, T_14, C_14, \ + N_15, AN_15, T_15, C_15, \ + N_16, AN_16, T_16, C_16, \ + N_17, AN_17, T_17, C_17, \ + N_18, AN_18, T_18, C_18, \ + N_19, AN_19, T_19, C_19, \ + N_20, AN_20, T_20, C_20, \ + N_21, AN_21, T_21, C_21, \ + N_22, AN_22, T_22, C_22, \ + N_23, AN_23, T_23, C_23) \ + public: \ + INTERFACE_COMMON(KIND) \ + DEFINE_ATTRIBUTE(N_0, T_0, C_0) \ + DEFINE_ATTRIBUTE(N_1, T_1, C_1) \ + DEFINE_ATTRIBUTE(N_2, T_2, C_2) \ + DEFINE_ATTRIBUTE(N_3, T_3, C_3) \ + DEFINE_ATTRIBUTE(N_4, T_4, C_4) \ + DEFINE_ATTRIBUTE(N_5, T_5, C_5) \ + DEFINE_ATTRIBUTE(N_6, T_6, C_6) \ + DEFINE_ATTRIBUTE(N_7, T_7, C_7) \ + DEFINE_ATTRIBUTE(N_8, T_8, C_8) \ + DEFINE_ATTRIBUTE(N_9, T_9, C_9) \ + DEFINE_ATTRIBUTE(N_10, T_10, C_10) \ + DEFINE_ATTRIBUTE(N_11, T_11, C_11) \ + DEFINE_ATTRIBUTE(N_12, T_12, C_12) \ + DEFINE_ATTRIBUTE(N_13, T_13, C_13) \ + DEFINE_ATTRIBUTE(N_14, T_14, C_14) \ + DEFINE_ATTRIBUTE(N_15, T_15, C_15) \ + DEFINE_ATTRIBUTE(N_16, T_16, C_16) \ + DEFINE_ATTRIBUTE(N_17, T_17, C_17) \ + DEFINE_ATTRIBUTE(N_18, T_18, C_18) \ + DEFINE_ATTRIBUTE(N_19, T_19, C_19) \ + DEFINE_ATTRIBUTE(N_20, T_20, C_20) \ + DEFINE_ATTRIBUTE(N_21, T_21, C_21) \ + DEFINE_ATTRIBUTE(N_22, T_22, C_22) \ + DEFINE_ATTRIBUTE(N_23, T_23, C_23) \ + protected: \ + START_INIT() \ + SET_ATTRIBUTE(N_0, T_0, AN_0) \ + SET_ATTRIBUTE(N_1, T_1, AN_1) \ + SET_ATTRIBUTE(N_2, T_2, AN_2) \ + SET_ATTRIBUTE(N_3, T_3, AN_3) \ + SET_ATTRIBUTE(N_4, T_4, AN_4) \ + SET_ATTRIBUTE(N_5, T_5, AN_5) \ + SET_ATTRIBUTE(N_6, T_6, AN_6) \ + SET_ATTRIBUTE(N_7, T_7, AN_7) \ + SET_ATTRIBUTE(N_8, T_8, AN_8) \ + SET_ATTRIBUTE(N_9, T_9, AN_9) \ + SET_ATTRIBUTE(N_10, T_10, AN_10) \ + SET_ATTRIBUTE(N_11, T_11, AN_11) \ + SET_ATTRIBUTE(N_12, T_12, AN_12) \ + SET_ATTRIBUTE(N_13, T_13, AN_13) \ + SET_ATTRIBUTE(N_14, T_14, AN_14) \ + SET_ATTRIBUTE(N_15, T_15, AN_15) \ + SET_ATTRIBUTE(N_16, T_16, AN_16) \ + SET_ATTRIBUTE(N_17, T_17, AN_17) \ + SET_ATTRIBUTE(N_18, T_18, AN_18) \ + SET_ATTRIBUTE(N_19, T_19, AN_19) \ + SET_ATTRIBUTE(N_20, T_20, AN_20) \ + SET_ATTRIBUTE(N_21, T_21, AN_21) \ + SET_ATTRIBUTE(N_22, T_22, AN_22) \ + SET_ATTRIBUTE(N_23, T_23, AN_23) \ + END_INIT() \ + public: + //-------------------------------------------------------------------------------------- #endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_MACRO_H_ */