X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConstructionAPI%2FConstructionAPI_Point.cpp;h=d4f073f1b2ceb5671d29e9c7f980bf963ec8a568;hb=dff2e776460fc98e6b234181479ec680a91e9623;hp=350c8857e8c483e6183390f2bd0b443d35c6b47b;hpb=3f02f2a44e42c854cb2b64c9817436e5a27788ab;p=modules%2Fshaper.git diff --git a/src/ConstructionAPI/ConstructionAPI_Point.cpp b/src/ConstructionAPI/ConstructionAPI_Point.cpp index 350c8857e..d4f073f1b 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Point.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 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 @@ -12,16 +12,18 @@ // // 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "ConstructionAPI_Point.h" +#include #include +#include +#include #include #include #include @@ -73,16 +75,86 @@ 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(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theObject, + const bool theIsCircularEdge, + const bool theIsXYZSelection) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) + { + if (theIsCircularEdge) { + setByCenterOfCircle(theObject); + } else if (theObject.shapeType() == "VERTEX" && theIsXYZSelection) { + // This is tricky way to get vertex shape. + fillAttribute(theObject, mypointToProject); + GeomShapePtr aShape = mypointToProject->value(); + if (!aShape.get()) { + ResultPtr aContext = mypointToProject->context(); + if (!aContext.get()) { + fillAttribute(ModelHighAPI_Selection(), mypointToProject); + return; + } + aShape = aContext->shape(); + } + + if (!aShape.get()) { + fillAttribute(ModelHighAPI_Selection(), mypointToProject); + return; + } + + GeomVertexPtr aVertex = aShape->vertex(); + if (!aVertex.get()) { + fillAttribute(ModelHighAPI_Selection(), mypointToProject); + return; + } + + GeomPointPtr aPnt = aVertex->point(); + if (!aPnt.get()) { + fillAttribute(ModelHighAPI_Selection(), mypointToProject); + return; + } + + fillAttribute(ModelHighAPI_Selection(), mypointToProject); + setByXYZ(aPnt->x(), aPnt->y(), aPnt->z()); + } else { + setByCenterOfGravity(theObject); + } + } +} + //================================================================================================== ConstructionAPI_Point::~ConstructionAPI_Point() { @@ -94,11 +166,8 @@ void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX, const ModelHighAPI_Double& theY, const ModelHighAPI_Double& theZ) { - //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod); - fillAttribute(theX, myx); - fillAttribute(theY, myy); - fillAttribute(theZ, myz); fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod); + fillAttribute(theX, theY, theZ, mypoint); execute(false); } @@ -128,9 +197,11 @@ void ConstructionAPI_Point::setByOffsetOnEdge(const ModelHighAPI_Selection& theE void ConstructionAPI_Point::setByProjectionOnEdge(const ModelHighAPI_Selection& theVertex, const ModelHighAPI_Selection& theEdge) { - fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_EDGE(), + fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod); - fillAttribute(theVertex, mypoinToProjectOnEdge); + fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE(), + myprojectionType); + fillAttribute(theVertex, mypointToProject); fillAttribute(theEdge, myedgeForPointProjection); execute(); @@ -140,56 +211,112 @@ void ConstructionAPI_Point::setByProjectionOnEdge(const ModelHighAPI_Selection& void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection& theVertex, const ModelHighAPI_Selection& theFace) { - fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_FACE(), + fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod); - fillAttribute(theVertex, mypoinToProjectOnFace); + fillAttribute(ConstructionPlugin_Point::PROJECTION_TYPE_ON_FACE(), + myprojectionType); + fillAttribute(theVertex, mypointToProject); fillAttribute(theFace, myfaceForPointProjection); 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::setByCenterOfGravity(const ModelHighAPI_Selection& theObject) +{ + fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY(), + mycreationMethod); + fillAttribute(ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_GRAVITY(), + mygeometricalPropertyType); + fillAttribute(theObject, myobjectForCenterOfGravity); + + execute(); +} + +//================================================================================================== +void ConstructionAPI_Point::setByCenterOfCircle(const ModelHighAPI_Selection& theObject) +{ + fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY(), + mycreationMethod); + fillAttribute(ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_CIRCLE(), + mygeometricalPropertyType); + fillAttribute(theObject, myobjectForCenterOfCircle); + + 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 << ", "; 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(); + theDumper << point(); + } 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() << ", "; @@ -200,10 +327,23 @@ void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const theDumper << ratio() << ", " << true; } theDumper << ", " << reverse()->value(); - } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_EDGE()) { - theDumper << mypoinToProjectOnEdge << ", " << myedgeForPointProjection; - } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_FACE()) { - theDumper << mypoinToProjectOnFace << ", " << myfaceForPointProjection; + } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION()) { + theDumper << pointToProject() << ", "; + if (projectionType()->value() == ConstructionPlugin_Point::PROJECTION_TYPE_ON_EDGE()) { + theDumper << edgeForPointProjection(); + } else { + theDumper << faceForPointProjection(); + } + } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_GEOMETRICAL_PROPERTY()) { + if (geometricalPropertyType()->value() == + ConstructionPlugin_Point::GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_GRAVITY()) + { + theDumper << objectForCenterOfGravity(); + } + else + { + theDumper << objectForCenterOfCircle() << ", " << true; + } } theDumper << ")" << std::endl; @@ -255,3 +395,30 @@ 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)); +} + +//================================================================================================== +PointPtr addPoint(const std::shared_ptr & thePart, + const ModelHighAPI_Selection& theObject, + const bool theIsCircularEdge) +{ + std::shared_ptr aFeature = thePart->addFeature(ConstructionAPI_Point::ID()); + return PointPtr(new ConstructionAPI_Point(aFeature, theObject, theIsCircularEdge)); +} + +//================================================================================================== +PointPtr addPointXYZ(const std::shared_ptr & thePart, + const ModelHighAPI_Selection& theObject) +{ + std::shared_ptr aFeature = thePart->addFeature(ConstructionAPI_Point::ID()); + return PointPtr(new ConstructionAPI_Point(aFeature, theObject, false, true)); +}