X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConstructionPlugin%2FConstructionPlugin_Point.cpp;h=fa0cf672a2d801930cc5c663b2e5b342fa5d9c56;hb=055d9413812e3ee5418d550fcb7a8ec0d58d0549;hp=61c20a9ee79333a3b6de3d27f32d63fd5df2d94e;hpb=489132d99e1d417d5c7ce93fed8fb8ee138befbc;p=modules%2Fshaper.git diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index 61c20a9ee..fa0cf672a 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -1,36 +1,190 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: ConstructionPlugin_Point.cxx // Created: 27 Mar 2014 // Author: Mikhail PONIKAROV #include "ConstructionPlugin_Point.h" -#include "ModelAPI_Session.h" -#include "ModelAPI_Document.h" -#include "ModelAPI_Data.h" -#include "ModelAPI_AttributeDouble.h" + +#include +#include +#include +#include #include + #include -#include -using namespace std; +#include +#include +#include +//================================================================================================== ConstructionPlugin_Point::ConstructionPlugin_Point() { } +//================================================================================================== +const std::string& ConstructionPlugin_Point::getKind() +{ + static std::string MY_KIND = ConstructionPlugin_Point::ID(); + return MY_KIND; +} + +//================================================================================================== void ConstructionPlugin_Point::initAttributes() { - data()->addAttribute(POINT_ATTR_X, ModelAPI_AttributeDouble::type()); - data()->addAttribute(POINT_ATTR_Y, ModelAPI_AttributeDouble::type()); - data()->addAttribute(POINT_ATTR_Z, ModelAPI_AttributeDouble::type()); + //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(EDGE(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId()); + data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId()); + + data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId()); + + data()->addAttribute(FIRST_LINE(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(SECOND_LINE(), ModelAPI_AttributeSelection::typeId()); + + data()->addAttribute(INTERSECTION_LINE(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(INTERSECTION_PLANE(), ModelAPI_AttributeSelection::typeId());*/ } +//================================================================================================== void ConstructionPlugin_Point::execute() { - boost::shared_ptr aPnt( - new GeomAPI_Pnt(data()->real(POINT_ATTR_X)->value(), data()->real(POINT_ATTR_Y)->value(), - data()->real(POINT_ATTR_Z)->value())); + GeomShapePtr aShape = createByXYZ(); + + /*GeomShapePtr aShape; + + std::string aCreationMethod = string(CREATION_METHOD())->value(); + if(aCreationMethod == CREATION_METHOD_BY_XYZ()) { + aShape = createByXYZ(); + } 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()) { + aShape = createByLineAndPlaneIntersection(); + }*/ + + if(!aShape.get()) { + return; + } - boost::shared_ptr aConstr = document()->createConstruction(data()); - aConstr->setShape(GeomAlgoAPI_PointBuilder::point(aPnt)); + std::shared_ptr aConstr = document()->createConstruction(data()); + aConstr->setShape(aShape); setResult(aConstr); } + +//================================================================================================== +bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult, + AISObjectPtr thePrs, + std::shared_ptr theDefaultPrs) +{ + bool isCustomized = theDefaultPrs.get() != NULL && + theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); + //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol + return true; +} + +//================================================================================================== +std::shared_ptr ConstructionPlugin_Point::createByXYZ() +{ + return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(), + real(Y())->value(), + real(Z())->value()); +} + +/*//================================================================================================== +std::shared_ptr ConstructionPlugin_Point::createByDistanceOnEdge() +{ + // Get edge. + AttributeSelectionPtr anEdgeSelection = selection(EDGE()); + GeomShapePtr aShape = anEdgeSelection->value(); + if(!aShape.get()) { + aShape = anEdgeSelection->context()->shape(); + } + std::shared_ptr anEdge(new GeomAPI_Edge(aShape)); + + // Get distance value and percent flag. + double aValue = real(DISTANCE_VALUE())->value(); + bool anIsPercent = boolean(DISTANCE_PERCENT())->value(); + + // Get reverse flag. + bool anIsReverse = boolean(REVERSE())->value(); + + return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse); +} + +//================================================================================================== +std::shared_ptr ConstructionPlugin_Point::createByProjection() +{ + // Get point. + AttributeSelectionPtr aPointSelection = selection(POINT()); + GeomShapePtr aPointShape = aPointSelection->value(); + if(!aPointShape.get()) { + aPointShape = aPointSelection->context()->shape(); + } + std::shared_ptr aVertex(new GeomAPI_Vertex(aPointShape)); + + // Get plane. + AttributeSelectionPtr aPlaneSelection = selection(PLANE()); + GeomShapePtr aPlaneShape = aPlaneSelection->value(); + if(!aPlaneShape.get()) { + aPlaneShape = aPlaneSelection->context()->shape(); + } + std::shared_ptr aFace(new GeomAPI_Face(aPlaneShape)); + + return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace); +} + +//================================================================================================== +std::shared_ptr ConstructionPlugin_Point::createByLinesIntersection() +{ + // Get first line. + AttributeSelectionPtr aFirstLineSelection= selection(FIRST_LINE()); + GeomShapePtr aFirstLineShape = aFirstLineSelection->value(); + if(!aFirstLineShape.get()) { + aFirstLineShape = aFirstLineSelection->context()->shape(); + } + std::shared_ptr aFirstEdge(new GeomAPI_Edge(aFirstLineShape)); + + // Get second line. + AttributeSelectionPtr aSecondLineSelection= selection(SECOND_LINE()); + GeomShapePtr aSecondLineShape = aSecondLineSelection->value(); + if(!aSecondLineShape.get()) { + aSecondLineShape = aSecondLineSelection->context()->shape(); + } + std::shared_ptr aSecondEdge(new GeomAPI_Edge(aSecondLineShape)); + + return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge); +} + +//================================================================================================== +std::shared_ptr ConstructionPlugin_Point::createByLineAndPlaneIntersection() +{ + // Get line. + AttributeSelectionPtr aLineSelection= selection(INTERSECTION_LINE()); + GeomShapePtr aLineShape = aLineSelection->value(); + if(!aLineShape.get()) { + aLineShape = aLineSelection->context()->shape(); + } + std::shared_ptr anEdge(new GeomAPI_Edge(aLineShape)); + + // Get plane. + AttributeSelectionPtr aPlaneSelection= selection(INTERSECTION_PLANE()); + GeomShapePtr aPlaneShape = aPlaneSelection->value(); + if(!aPlaneShape.get()) { + aPlaneShape = aPlaneSelection->context()->shape(); + } + std::shared_ptr aFace(new GeomAPI_Face(aPlaneShape)); + + return GeomAlgoAPI_PointBuilder::vertexByIntersection(anEdge, aFace); +}*/