X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConstructionPlugin%2FConstructionPlugin_Point.cpp;h=087cfd91deaf5d37e9da75790cef97f5e628747d;hb=29ae5ac5706b94b3df50136a545649be524fd2a3;hp=e6ee010c24e08c03c7eb08ae2809a6a1523a1a24;hpb=e9bc8b0ef4a083909ae41172e6ac891136051c91;p=modules%2Fshaper.git diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index e6ee010c2..087cfd91d 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2020 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,16 @@ // // 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 "ConstructionPlugin_Point.h" #include #include +#include #include #include #include @@ -29,10 +29,16 @@ #include #include +#include +#include + #include #include #include #include +#include + +#include //================================================================================================== ConstructionPlugin_Point::ConstructionPlugin_Point() @@ -49,9 +55,7 @@ const std::string& ConstructionPlugin_Point::getKind() //================================================================================================== void ConstructionPlugin_Point::initAttributes() { - data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(POINT3D(), GeomDataAPI_Point::typeId()); data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId()); @@ -76,10 +80,13 @@ void ConstructionPlugin_Point::initAttributes() 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()); + + data()->addAttribute(GEOMETRICAL_PROPERTY_TYPE(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(OBJECT_FOR_CENTER_OF_GRAVITY(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(OBJECT_FOR_CENTER_OF_CIRCLE(), ModelAPI_AttributeSelection::typeId()); } //================================================================================================== @@ -123,6 +130,13 @@ void ConstructionPlugin_Point::execute() } else { aShape = createByPlanesIntersection(); } + } else if (aCreationMethod == CREATION_METHOD_BY_GEOMETRICAL_PROPERTY()) { + std::string aGeometricalPropertyType = string(GEOMETRICAL_PROPERTY_TYPE())->value(); + if (aGeometricalPropertyType == GEOMETRICAL_PROPERTY_TYPE_BY_CENTER_OF_GRAVITY()) { + aShape = createByCenterOfGravity(); + } else { + aShape = createByCenterOfCircle(); + } } if(!aShape.get()) { @@ -132,27 +146,42 @@ void ConstructionPlugin_Point::execute() removeResults(1); // for case the point type was switched from multi-results type std::shared_ptr aConstr = document()->createConstruction(data()); + aConstr->setInfinite(true); aConstr->setShape(aShape); setResult(aConstr); } //================================================================================================== bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult, - AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs) + AISObjectPtr thePrs) { - bool isCustomized = theDefaultPrs.get() != NULL && - theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); + std::vector aColor; + // get color from the attribute of the result + if (theResult.get() != NULL && + theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) { + AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID()); + if (aColorAttr.get() && aColorAttr->size()) { + aColor.push_back(aColorAttr->value(0)); + aColor.push_back(aColorAttr->value(1)); + aColor.push_back(aColorAttr->value(2)); + } + } + if (aColor.empty()) + aColor = Config_PropManager::color("Visualization", COLOR_NAME()); + + bool isCustomized = false; + if (aColor.size() == 3) + isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]); //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol - return true; + return isCustomized; } //================================================================================================== std::shared_ptr ConstructionPlugin_Point::createByXYZ() { - return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(), - real(Y())->value(), - real(Z())->value()); + AttributePointPtr aPoint = + std::dynamic_pointer_cast(data()->attribute(POINT3D())); + return GeomAlgoAPI_PointBuilder::vertex(aPoint->x(), aPoint->y(), aPoint->z()); } //================================================================================================== @@ -259,7 +288,14 @@ std::list > if(!aLineShape.get()) { aLineShape = aLineSelection->context()->shape(); } - std::shared_ptr anEdge(new GeomAPI_Edge(aLineShape)); + GeomEdgePtr anEdge; + if (aLineShape->isEdge()) { + anEdge = aLineShape->edge(); + } + else if (aLineShape->isCompound()) { + GeomAPI_ShapeIterator anIt(aLineShape); + anEdge = anIt.current()->edge(); + } // Get plane. AttributeSelectionPtr aPlaneSelection= selection(INTERSECTION_PLANE()); @@ -267,7 +303,14 @@ std::list > if(!aPlaneShape.get()) { aPlaneShape = aPlaneSelection->context()->shape(); } - std::shared_ptr aFace(new GeomAPI_Face(aPlaneShape)); + GeomFacePtr aFace; + if (aPlaneShape->isFace()) { + aFace = aPlaneShape->face(); + } + else if (aPlaneShape->isCompound()) { + GeomAPI_ShapeIterator anIt(aPlaneShape); + aFace = anIt.current()->face(); + } if (!string(USE_OFFSET())->value().empty()) { double anOffset = real(OFFSET())->value(); @@ -278,8 +321,7 @@ std::list > } } - return GeomAlgoAPI_ShapeTools::intersect(anEdge, aFace, - aPlaneSelection->context()->groupName() == ModelAPI_ResultConstruction::group()); + return GeomAlgoAPI_ShapeTools::intersect(anEdge, aFace); } //================================================================================================== @@ -326,3 +368,45 @@ std::shared_ptr ConstructionPlugin_Point::createByPlanesIntersec return aVertex; } + +//================================================================================================== +std::shared_ptr ConstructionPlugin_Point::createByCenterOfGravity() +{ + // Get shape. + AttributeSelectionPtr aShapeSelection = selection(OBJECT_FOR_CENTER_OF_GRAVITY()); + GeomShapePtr aShape = aShapeSelection->value(); + if (!aShape.get()) + { + aShape = aShapeSelection->context()->shape(); + } + + std::shared_ptr aVertex; + std::shared_ptr aPnt = GeomAlgoAPI_ShapeTools::centreOfMass(aShape); + if (aPnt.get()) + { + aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z())); + } + + return aVertex; +} + +//================================================================================================== +std::shared_ptr ConstructionPlugin_Point::createByCenterOfCircle() +{ + // Get shape. + AttributeSelectionPtr aShapeSelection = selection(OBJECT_FOR_CENTER_OF_CIRCLE()); + GeomShapePtr aShape = aShapeSelection->value(); + if (!aShape.get()) { + aShape = aShapeSelection->context()->shape(); + } + std::shared_ptr anEdge(new GeomAPI_Edge(aShape)); + std::shared_ptr aCirc = anEdge->circle(); + + std::shared_ptr aVertex; + std::shared_ptr aPnt = aCirc->center(); + if (aPnt.get()) { + aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z())); + } + + return aVertex; +}