#include <TopoDS_Shape.hxx>
#include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
#include <BRep_Tool.hxx>
#include <Geom_Curve.hxx>
#include <Geom_Line.hxx>
#include <Geom_Circle.hxx>
+#include <GeomAdaptor_Curve.hxx>
#include <gp_Ax1.hxx>
GeomAPI_Edge::GeomAPI_Edge()
}
return boost::shared_ptr<GeomAPI_Circ>(); // not circle
}
+
+
+bool GeomAPI_Edge::isEqual(boost::shared_ptr<GeomAPI_Shape> theEdge)
+{
+ const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+ const TopoDS_Shape& aInShape = theEdge->impl<TopoDS_Shape>();
+
+ double aMyStart, aMyEnd;
+ Handle(Geom_Curve) aMyCurve = BRep_Tool::Curve(TopoDS::Edge(aMyShape), aMyStart, aMyEnd);
+ double aInStart, aInEnd;
+ Handle(Geom_Curve) aInCurve = BRep_Tool::Curve(TopoDS::Edge(aInShape), aInStart, aInEnd);
+
+ // Check that curves a the same type
+ GeomAdaptor_Curve aMyAdaptor(aMyCurve);
+ GeomAdaptor_Curve aInAdaptor(aInCurve);
+ if (aMyAdaptor.GetType() != aInAdaptor.GetType())
+ return false;
+
+ // Check that end point parameters are the same
+ if ((aMyStart != aInStart) || (aMyEnd != aInEnd))
+ return false;
+
+ // Check that end points are equal
+ gp_Pnt aMyPnt1 = aMyAdaptor.Value(aMyStart);
+ gp_Pnt aMyPnt2 = aMyAdaptor.Value(aMyEnd);
+ gp_Pnt aInPnt1 = aInAdaptor.Value(aInStart);
+ gp_Pnt aInPnt2 = aInAdaptor.Value(aInEnd);
+
+ if ((!aMyPnt1.IsEqual(aInPnt1, Precision::Confusion())) ||
+ (!aMyPnt2.IsEqual(aInPnt2, Precision::Confusion())))
+ return false;
+
+ return true;
+}
\ No newline at end of file
/// Returns a circle if edge is based on the cirsle curve
boost::shared_ptr<GeomAPI_Circ> circle();
+
+ /// Returns true if the current edge is geometrically equal to the given edge
+ bool isEqual(boost::shared_ptr<GeomAPI_Shape> theEdge);
};
#endif
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_ResultConstruction.h>
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Dir.h>
#include <GeomAPI_Pln.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Edge.h>
#include <GeomAPI_Dir.h>
#include <GeomAPI_XYZ.h>
#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
#ifdef _DEBUG
#include <QDebug>
if (aShape.ShapeType() != TopAbs_EDGE)
return ResultPtr();
+ // Check that we already have such external edge
+ boost::shared_ptr<GeomAPI_Edge> aInEdge = boost::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge());
+ aInEdge->setImpl(new TopoDS_Shape(aShape));
+ 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;
}
return false;
}
+
+ResultPtr PartSet_Tools::findExternalEdge(CompositeFeaturePtr theSketch, boost::shared_ptr<GeomAPI_Edge> theEdge)
+{
+ for (int i = 0; i < theSketch->numberOfSubs(); i++) {
+ FeaturePtr aFeature = theSketch->subFeature(i);
+ boost::shared_ptr<SketchPlugin_Feature> aSketchFea =
+ boost::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 =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aIt);
+ if (aRes) {
+ boost::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
+ if (aShape) {
+ if (theEdge->isEqual(aShape))
+ return aRes;
+ }
+ }
+ }
+ }
+ }
+ }
+ return ResultPtr();
+}
\ No newline at end of file
#include <QList>
#include <ModelAPI_CompositeFeature.h>
-#include <TopoDS_Edge.hxx>
#include <boost/shared_ptr.hpp>
class GeomAPI_Pln;
class GeomAPI_Pnt2d;
class GeomAPI_Pnt;
+class GeomAPI_Edge;
/*!
\class PartSet_Tools
static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
const ModuleBase_ViewerPrs& thePrs);
+ /// Returns Result object if the given skietch contains external edge equal to the given
+ /// \param theSketch - the sketch feature
+ /// \param theEdge - the edge
+ /// \return result object with external edge if it is found
+ static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, boost::shared_ptr<GeomAPI_Edge> theEdge);
};
#endif
/// Returns true is sketch element is under the rigid constraint
SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;}
+ bool isExternal() const
+ {
+ AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
+ if (aAttr)
+ return aAttr->context();
+ return false;
+ }
+
/// Returns the sketch of this feature
SketchPlugin_Sketch* sketch();
protected: