--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomAPI_Vertex.cpp
+// Created: 24 Jul 2014
+// Author: Artem ZHIDKOV
+
+#include<GeomAPI_Vertex.h>
+#include<GeomAPI_Pnt.h>
+
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <BRep_Tool.hxx>
+#include <gp_Pnt.hxx>
+#include <Precision.hxx>
+
+GeomAPI_Vertex::GeomAPI_Vertex()
+ : GeomAPI_Shape()
+{
+}
+
+GeomAPI_Vertex::GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Shape>& theShape)
+{
+ if (!theShape->isNull() && theShape->isVertex()) {
+ setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
+ }
+}
+
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Vertex::point()
+{
+ const TopoDS_Shape& aShape = const_cast<GeomAPI_Vertex*>(this)->impl<TopoDS_Shape>();
+ TopoDS_Vertex aVertex = TopoDS::Vertex(aShape);
+ gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
+ return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
+}
+
+bool GeomAPI_Vertex::isEqual(std::shared_ptr<GeomAPI_Shape> theVert)
+{
+ const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Vertex*>(this)->impl<TopoDS_Shape>();
+ const TopoDS_Shape& aInShape = theVert->impl<TopoDS_Shape>();
+
+ 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());
+}
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Edge.h>
+#include <GeomAPI_Vertex.h>
#include <GeomAPI_Dir.h>
#include <GeomAPI_XYZ.h>
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
#include <ModuleBase_ViewerPrs.h>
const ObjectPtr& theObject,
CompositeFeaturePtr theSketch)
{
- if (theShape.ShapeType() != TopAbs_EDGE)
- return ResultPtr();
-
- // Check that we already have such external edge
- std::shared_ptr<GeomAPI_Edge> aInEdge = std::shared_ptr<GeomAPI_Edge>(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<GeomAPI_Edge> aInEdge = std::shared_ptr<GeomAPI_Edge>(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<ModelAPI_AttributeSelection>
- (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
+ if (aMyFeature) {
+ DataPtr aData = aMyFeature->data();
+ AttributeSelectionPtr anAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
- ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
- if (anAttr && aRes) {
- std::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
- anEdge->setImpl(new TopoDS_Shape(theShape));
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (anAttr && aRes) {
+ std::shared_ptr<GeomAPI_Shape> 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<GeomAPI_Vertex> aInVert = std::shared_ptr<GeomAPI_Vertex>(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<ModelAPI_AttributeSelection>
+ (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
+
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (anAttr && aRes) {
+ std::shared_ptr<GeomAPI_Shape> 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();
return ResultPtr();
}
+
+ResultPtr PartSet_Tools::findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Vertex> theVert)
+{
+ for (int i = 0; i < theSketch->numberOfSubs(); i++) {
+ FeaturePtr aFeature = theSketch->subFeature(i);
+ std::shared_ptr<SketchPlugin_Feature> aSketchFea =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+ if (aSketchFea) {
+ if (aSketchFea->isExternal()) {
+ std::list<ResultPtr> aResults = aSketchFea->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+ ResultConstructionPtr aRes =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aIt);
+ if (aRes) {
+ std::shared_ptr<GeomAPI_Shape> 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)
{
FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(mySelectedObject);
if (aSelectedFeature == myFeature) // In order to avoid selection of the same object
return false;
+ std::shared_ptr<SketchPlugin_Feature> aSPFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
+ if ((!aSPFeature) && (!myShape->isNull())) {
+ // Processing of external (non-sketch) object
+ ObjectPtr aObj = PartSet_Tools::createFixedObjectByEdge(myShape->impl<TopoDS_Shape>(),
+ 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<ModelAPI_AttributeRefAttr>(aAttr);
+ if (aRefAttr) {
+ TopoDS_Shape aShape = myShape->impl<TopoDS_Shape>();
+ 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<ModelAPI_AttributeRefAttr>(aAttr);
- if (aRefAttr) {
- TopoDS_Shape aShape = myShape->impl<TopoDS_Shape>();
- 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();
if (aObj) {
PartSet_WidgetConstraintShapeSelector* that = (PartSet_WidgetConstraintShapeSelector*) this;
that->mySelectedObject = aObj;
- }
+ } else
+ return false;
}
}
return ModuleBase_WidgetShapeSelector::storeValue();