X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConstructionPlugin%2FConstructionPlugin_Point.cpp;h=bb59c3d550acee82307197fd38c07ec3a372ee5b;hb=9d8267a424a809d0f96593b13f8472666553ce2e;hp=08ff70a3a7a2ed8a7f5cdba439c975df2f0fe4ef;hpb=a32b8e5b427c1d2ebb4b90eeda4c9ca97c70f1a9;p=modules%2Fshaper.git diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index 08ff70a3a..bb59c3d55 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -29,6 +29,9 @@ #include #include +#include +#include + #include #include #include @@ -49,29 +52,38 @@ 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()); - /*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(INTERSECTION_LINE_1(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(INTERSECTION_LINE_2(), 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()); - data()->addAttribute(USE_OFFSET(), ModelAPI_AttributeString::typeId()); data()->addAttribute(OFFSET(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(REVERSE_OFFSET(), ModelAPI_AttributeBoolean::typeId()); + + data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(OFFSET_TYPE(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(DISTANCE(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(RATIO(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId()); + + data()->addAttribute(POINT_TO_PROJECT(), ModelAPI_AttributeSelection::typeId()); + 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()); + + 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()); } //================================================================================================== @@ -85,26 +97,42 @@ void ConstructionPlugin_Point::execute() 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()) { - // 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); + if (string(PROJECTION_TYPE())->value() == PROJECTION_TYPE_ON_EDGE()) { + aShape = createByProjectionOnEdge(); + } else { + aShape = createByProjectionOnFace(); + } + } 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(); + } + } 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(); } } @@ -133,12 +161,12 @@ bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult, //================================================================================================== 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()); } -/*//================================================================================================== +//================================================================================================== std::shared_ptr ConstructionPlugin_Point::createByDistanceOnEdge() { // Get edge. @@ -150,8 +178,15 @@ std::shared_ptr ConstructionPlugin_Point::createByDistanceOnEdge 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(); + double aValue; + bool anIsPercent = false; + if (string(OFFSET_TYPE())->value() == OFFSET_TYPE_BY_DISTANCE()) { + aValue = real(DISTANCE())->value(); + anIsPercent = false; + } else { + aValue = real(RATIO())->value() * 100.0; + anIsPercent = true; + } // Get reverse flag. bool anIsReverse = boolean(REVERSE())->value(); @@ -160,10 +195,32 @@ std::shared_ptr ConstructionPlugin_Point::createByDistanceOnEdge } //================================================================================================== -std::shared_ptr ConstructionPlugin_Point::createByProjection() +std::shared_ptr ConstructionPlugin_Point::createByProjectionOnEdge() { // Get point. - AttributeSelectionPtr aPointSelection = selection(POINT()); + AttributeSelectionPtr aPointSelection = selection(POINT_TO_PROJECT()); + GeomShapePtr aPointShape = aPointSelection->value(); + if (!aPointShape.get()) { + aPointShape = aPointSelection->context()->shape(); + } + std::shared_ptr aVertex(new GeomAPI_Vertex(aPointShape)); + + // Get edge. + AttributeSelectionPtr anEdgeSelection = selection(EDGE_FOR_POINT_PROJECTION()); + GeomShapePtr anEdgeShape = anEdgeSelection->value(); + if (!anEdgeShape.get()) { + anEdgeShape = anEdgeSelection->context()->shape(); + } + std::shared_ptr anEdge(new GeomAPI_Edge(anEdgeShape)); + + return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, anEdge); +} + +//================================================================================================== +std::shared_ptr ConstructionPlugin_Point::createByProjectionOnFace() +{ + // Get point. + AttributeSelectionPtr aPointSelection = selection(POINT_TO_PROJECT()); GeomShapePtr aPointShape = aPointSelection->value(); if(!aPointShape.get()) { aPointShape = aPointSelection->context()->shape(); @@ -171,7 +228,7 @@ std::shared_ptr ConstructionPlugin_Point::createByProjection() std::shared_ptr aVertex(new GeomAPI_Vertex(aPointShape)); // Get plane. - AttributeSelectionPtr aPlaneSelection = selection(PLANE()); + AttributeSelectionPtr aPlaneSelection = selection(FACE_FOR_POINT_PROJECTION()); GeomShapePtr aPlaneShape = aPlaneSelection->value(); if(!aPlaneShape.get()) { aPlaneShape = aPlaneSelection->context()->shape(); @@ -185,7 +242,7 @@ std::shared_ptr ConstructionPlugin_Point::createByProjection() 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(); @@ -193,7 +250,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(); @@ -202,7 +259,6 @@ std::shared_ptr ConstructionPlugin_Point::createByLinesIntersect return GeomAlgoAPI_PointBuilder::vertexByIntersection(aFirstEdge, aSecondEdge); } -*/ //================================================================================================== std::list > @@ -236,3 +292,90 @@ 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; +} + +//================================================================================================== +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; +}