From: vsv Date: Tue, 16 Dec 2014 13:05:46 +0000 (+0300) Subject: Process non-sketch Points for Distance constraint X-Git-Tag: before_slalome_7.5.1~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3527295683587eb7ed5cc6c37aa7fe65bd27da64;p=modules%2Fshaper.git Process non-sketch Points for Distance constraint --- diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index eec0e4d2c..2df13f8cc 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -27,7 +27,8 @@ SET(PROJECT_HEADERS GeomAPI_IPresentable.h GeomAPI_Curve.h GeomAPI_DataMapOfShapeShape.h - GeomAPI_ICustomPrs.h + GeomAPI_ICustomPrs.h + GeomAPI_Vertex.h ) SET(PROJECT_SOURCES @@ -50,6 +51,7 @@ SET(PROJECT_SOURCES GeomAPI_AISObject.cpp GeomAPI_Curve.cpp GeomAPI_DataMapOfShapeShape.cpp + GeomAPI_Vertex.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/GeomAPI/GeomAPI_Vertex.cpp b/src/GeomAPI/GeomAPI_Vertex.cpp new file mode 100644 index 000000000..6c3d05e35 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Vertex.cpp @@ -0,0 +1,50 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAPI_Vertex.cpp +// Created: 24 Jul 2014 +// Author: Artem ZHIDKOV + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +GeomAPI_Vertex::GeomAPI_Vertex() + : GeomAPI_Shape() +{ +} + +GeomAPI_Vertex::GeomAPI_Vertex(const std::shared_ptr& theShape) +{ + if (!theShape->isNull() && theShape->isVertex()) { + setImpl(new TopoDS_Shape(theShape->impl())); + } +} + +std::shared_ptr GeomAPI_Vertex::point() +{ + const TopoDS_Shape& aShape = const_cast(this)->impl(); + TopoDS_Vertex aVertex = TopoDS::Vertex(aShape); + gp_Pnt aPoint = BRep_Tool::Pnt(aVertex); + return std::shared_ptr(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z())); +} + +bool GeomAPI_Vertex::isEqual(std::shared_ptr theVert) +{ + const TopoDS_Shape& aMyShape = const_cast(this)->impl(); + const TopoDS_Shape& aInShape = theVert->impl(); + + TopoDS_Vertex aVertex1 = TopoDS::Vertex(aMyShape); + gp_Pnt aPoint1 = BRep_Tool::Pnt(aVertex1); + + TopoDS_Vertex aVertex2 = TopoDS::Vertex(aInShape); + gp_Pnt aPoint2 = BRep_Tool::Pnt(aVertex2); + + return aPoint1.IsEqual(aPoint2, Precision::Confusion()); +} diff --git a/src/GeomAPI/GeomAPI_Vertex.h b/src/GeomAPI/GeomAPI_Vertex.h new file mode 100644 index 000000000..fab2840b4 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Vertex.h @@ -0,0 +1,36 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAPI_Vertex.hxx +// Created: 16 Dec 2014 +// Author: Vitaly Smetannikov + +#ifndef GeomAPI_Vertex_H_ +#define GeomAPI_Vertex_H_ + +#include + +class GeomAPI_Pnt; + +/**\class GeomAPI_Vertex +* \ingroup DataModel + * \brief Interface to the vertex object + */ + +class GEOMAPI_EXPORT GeomAPI_Vertex : public GeomAPI_Shape +{ +public: + /// Creation of empty (null) shape + GeomAPI_Vertex(); + + /// Creation of edge by the edge-shape + GeomAPI_Vertex(const std::shared_ptr& theShape); + + /// Returns the first vertex coordinates of the edge + std::shared_ptr point(); + + /// Returns true if the current edge is geometrically equal to the given edge + bool isEqual(std::shared_ptr theVert); +}; + +#endif + diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 41182b674..78df67edb 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -35,6 +36,7 @@ #include #include #include +#include #include @@ -402,56 +404,87 @@ ResultPtr PartSet_Tools::createFixedObjectByEdge(const TopoDS_Shape& theShape, const ObjectPtr& theObject, CompositeFeaturePtr theSketch) { - if (theShape.ShapeType() != TopAbs_EDGE) - return ResultPtr(); - - // Check that we already have such external edge - std::shared_ptr aInEdge = std::shared_ptr(new GeomAPI_Edge()); - aInEdge->setImpl(new TopoDS_Shape(theShape)); - ResultPtr aResult = findExternalEdge(theSketch, aInEdge); - if (aResult) - return aResult; - - // If not found then we have to create new - Standard_Real aStart, aEnd; - Handle(V3d_View) aNullView; - FeaturePtr aMyFeature; - - Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(theShape), aStart, aEnd); - GeomAdaptor_Curve aAdaptor(aCurve); - if (aAdaptor.GetType() == GeomAbs_Line) { - // Create line - aMyFeature = theSketch->addFeature(SketchPlugin_Line::ID()); - } else if (aAdaptor.GetType() == GeomAbs_Circle) { - if (aAdaptor.IsClosed()) { - // Create circle - aMyFeature = theSketch->addFeature(SketchPlugin_Circle::ID()); - } else { - // Create arc - aMyFeature = theSketch->addFeature(SketchPlugin_Arc::ID()); + if (theShape.ShapeType() == TopAbs_EDGE) { + // Check that we already have such external edge + std::shared_ptr aInEdge = std::shared_ptr(new GeomAPI_Edge()); + aInEdge->setImpl(new TopoDS_Shape(theShape)); + ResultPtr aResult = findExternalEdge(theSketch, aInEdge); + if (aResult) + return aResult; + + // If not found then we have to create new + Standard_Real aStart, aEnd; + Handle(V3d_View) aNullView; + FeaturePtr aMyFeature; + + Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(theShape), aStart, aEnd); + GeomAdaptor_Curve aAdaptor(aCurve); + if (aAdaptor.GetType() == GeomAbs_Line) { + // Create line + aMyFeature = theSketch->addFeature(SketchPlugin_Line::ID()); + } else if (aAdaptor.GetType() == GeomAbs_Circle) { + if (aAdaptor.IsClosed()) { + // Create circle + aMyFeature = theSketch->addFeature(SketchPlugin_Circle::ID()); + } else { + // Create arc + aMyFeature = theSketch->addFeature(SketchPlugin_Arc::ID()); + } } - } - if (aMyFeature) { - DataPtr aData = aMyFeature->data(); - AttributeSelectionPtr anAttr = - std::dynamic_pointer_cast - (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID())); + if (aMyFeature) { + DataPtr aData = aMyFeature->data(); + AttributeSelectionPtr anAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID())); - ResultPtr aRes = std::dynamic_pointer_cast(theObject); - if (anAttr && aRes) { - std::shared_ptr anEdge(new GeomAPI_Shape); - anEdge->setImpl(new TopoDS_Shape(theShape)); + ResultPtr aRes = std::dynamic_pointer_cast(theObject); + if (anAttr && aRes) { + std::shared_ptr anEdge(new GeomAPI_Shape); + anEdge->setImpl(new TopoDS_Shape(theShape)); - anAttr->setValue(aRes, anEdge); + anAttr->setValue(aRes, anEdge); - aMyFeature->execute(); + aMyFeature->execute(); - // fix this edge - FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID()); - aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())-> - setObject(aMyFeature->lastResult()); + // fix this edge + FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID()); + aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())-> + setObject(aMyFeature->lastResult()); - return aMyFeature->lastResult(); + return aMyFeature->lastResult(); + } + } + } + if (theShape.ShapeType() == TopAbs_VERTEX) { + std::shared_ptr aInVert = std::shared_ptr(new GeomAPI_Vertex()); + aInVert->setImpl(new TopoDS_Shape(theShape)); + ResultPtr aResult = findExternalVertex(theSketch, aInVert); + if (aResult) + return aResult; + + FeaturePtr aMyFeature = theSketch->addFeature(SketchPlugin_Point::ID()); + + if (aMyFeature) { + DataPtr aData = aMyFeature->data(); + AttributeSelectionPtr anAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID())); + + ResultPtr aRes = std::dynamic_pointer_cast(theObject); + if (anAttr && aRes) { + std::shared_ptr aVert(new GeomAPI_Shape); + aVert->setImpl(new TopoDS_Shape(theShape)); + + anAttr->setValue(aRes, aVert); + aMyFeature->execute(); + + // fix this edge + FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID()); + aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())-> + setObject(aMyFeature->lastResult()); + + return aMyFeature->lastResult(); + } } } return ResultPtr(); @@ -494,6 +527,35 @@ ResultPtr PartSet_Tools::findExternalEdge(CompositeFeaturePtr theSketch, std::sh return ResultPtr(); } + +ResultPtr PartSet_Tools::findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr theVert) +{ + for (int i = 0; i < theSketch->numberOfSubs(); i++) { + FeaturePtr aFeature = theSketch->subFeature(i); + std::shared_ptr aSketchFea = + std::dynamic_pointer_cast(aFeature); + if (aSketchFea) { + if (aSketchFea->isExternal()) { + std::list aResults = aSketchFea->results(); + std::list::const_iterator aIt; + for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { + ResultConstructionPtr aRes = + std::dynamic_pointer_cast(*aIt); + if (aRes) { + std::shared_ptr aShape = aRes->shape(); + if (aShape) { + if (theVert->isEqual(aShape)) + return aRes; + } + } + } + } + } + } + return ResultPtr(); +} + + bool PartSet_Tools::hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch, Handle_V3d_View theView, double& theX, double& theY) { diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index ec1afea13..e3579c9f5 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -30,6 +30,7 @@ class GeomAPI_Pln; class GeomAPI_Pnt2d; class GeomAPI_Pnt; class GeomAPI_Edge; +class GeomAPI_Vertex; /*! \class PartSet_Tools @@ -160,6 +161,12 @@ class PARTSET_EXPORT PartSet_Tools /// \return result object with external edge if it is found static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr theEdge); + /// Returns Result object if the given sketch contains external vertex equal to the given + /// \param theSketch - the sketch feature + /// \param theVert - the vertex + /// \return result object with external vertex if it is found + static ResultPtr findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr theVert); + /// Returns whether the selected presentation has a shape with the vertex type /// \param thePrs a selected presentation /// \param theSketch the sketch feature diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index fe34cc859..04f026112 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -19,22 +19,35 @@ bool PartSet_WidgetShapeSelector::storeValue() const FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(mySelectedObject); if (aSelectedFeature == myFeature) // In order to avoid selection of the same object return false; + std::shared_ptr aSPFeature = + std::dynamic_pointer_cast(aSelectedFeature); + if ((!aSPFeature) && (!myShape->isNull())) { + // Processing of external (non-sketch) object + ObjectPtr aObj = PartSet_Tools::createFixedObjectByEdge(myShape->impl(), + mySelectedObject, mySketch); + if (aObj) { + PartSet_WidgetShapeSelector* that = (PartSet_WidgetShapeSelector*) this; + that->mySelectedObject = aObj; + } else + return false; + } else { + // Processing of sketch object + DataPtr aData = myFeature->data(); + if (myUseSubShapes && myShape) { + AttributePtr aAttr = aData->attribute(attributeID()); + AttributeRefAttrPtr aRefAttr = + std::dynamic_pointer_cast(aAttr); + if (aRefAttr) { + TopoDS_Shape aShape = myShape->impl(); + AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(mySelectedObject, aShape, mySketch); + if (mySelectedObject) + aRefAttr->setObject(mySelectedObject); + if (aPntAttr) + aRefAttr->setAttr(aPntAttr); - DataPtr aData = myFeature->data(); - if (myUseSubShapes && myShape) { - AttributePtr aAttr = aData->attribute(attributeID()); - AttributeRefAttrPtr aRefAttr = - std::dynamic_pointer_cast(aAttr); - if (aRefAttr) { - TopoDS_Shape aShape = myShape->impl(); - AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(mySelectedObject, aShape, mySketch); - if (mySelectedObject) - aRefAttr->setObject(mySelectedObject); - if (aPntAttr) - aRefAttr->setAttr(aPntAttr); - - updateObject(myFeature); - return true; + updateObject(myFeature); + return true; + } } } return ModuleBase_WidgetShapeSelector::storeValue(); @@ -53,7 +66,8 @@ bool PartSet_WidgetConstraintShapeSelector::storeValue() const if (aObj) { PartSet_WidgetConstraintShapeSelector* that = (PartSet_WidgetConstraintShapeSelector*) this; that->mySelectedObject = aObj; - } + } else + return false; } } return ModuleBase_WidgetShapeSelector::storeValue();