// Author: Mikhail PONIKAROV
#include<GeomAPI_Curve.h>
+#include<GeomAPI_Pnt.h>
#include <TopoDS_Shape.hxx>
#include <Geom_Curve.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS.hxx>
+#include <GeomAdaptor_Curve.hxx>
#define MY_CURVE (*(static_cast<Handle_Geom_Curve*>(myImpl)))
GeomAPI_Curve::GeomAPI_Curve()
- : GeomAPI_Interface(new Handle_Geom_Curve())
+ : GeomAPI_Interface(new Handle_Geom_Curve()), myStart(0), myEnd(1)
{
}
const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
TopoDS_Edge anEdge = TopoDS::Edge(aShape);
if (!anEdge.IsNull()) {
- Standard_Real aStart, anEnd;
- Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aStart, anEnd);
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, myStart, myEnd);
if (!aCurve.IsNull()) {
setImpl(new Handle(Geom_Curve)(aCurve));
}
{
return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Circle);
}
+
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Curve::getPoint(double theParam)
+{
+ GeomAdaptor_Curve aAdaptor(MY_CURVE, myStart, myEnd);
+ gp_Pnt aPnt = aAdaptor.Value(theParam);
+ return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
+}
#include <GeomAPI_Shape.h>
#include <memory>
+class GeomAPI_Pnt;
+
/**\class GeomAPI_Curve
* \ingroup DataModel
* \brief Interface to the generic curve object
/// Returns whether the curve is circular
virtual bool isCircle() const;
+ /// Returns start parameter of the curve
+ double startParam() const { return myStart; }
+
+ /// Returns end parameter of the curve
+ double endParam() const { return myEnd; }
+
+ /// Returns point on the curve by parameter
+ /// \param theParam parameter on the curve
+ std::shared_ptr<GeomAPI_Pnt> getPoint(double theParam);
+
+private:
+ double myStart;
+ double myEnd;
};
#endif
prepareAspect();
ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
- std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getLine(aObj1);
+ std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
if (aLine1.get() == NULL)
return;
ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
- std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getLine(aObj1);
+ std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
if (aLine1.get() == NULL)
return;
- std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getLine(aObj2);
+ std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getShape(aObj2);
if (aLine2.get() == NULL)
return;
ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
- std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getLine(aObj1);
+ std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
if (aLine1.get() == NULL)
return;
- std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getLine(aObj2);
+ std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getShape(aObj2);
if (aLine2.get() == NULL)
return;
#include "SketcherPrs_Tools.h"
#include <GeomAPI_Edge.h>
+#include <GeomAPI_Curve.h>
+#include <GeomAPI_Vertex.h>
+#include <GeomAPI_Dir.h>
static const int MyStep = 20;
}
}
-gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theLine,
+gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape,
Handle(SketcherPrs_SymbolPrs) thePrs)
{
- std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getLine(theLine);
- std::shared_ptr<GeomAPI_Edge> aEdge =
- std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aShape));
+ std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(theShape);
+ gp_Pnt aP; // Central point
+ gp_Vec aVec1; // main vector
+ if (aShape->isEdge()) {
+ std::shared_ptr<GeomAPI_Curve> aCurve = std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(aShape));
+ std::shared_ptr<GeomAPI_Pnt> aPnt1; // Start point of main vector
+ std::shared_ptr<GeomAPI_Pnt> aPnt2; // End point of main vector
+ if (aCurve->isLine()) {
+ std::shared_ptr<GeomAPI_Edge> aEdge =
+ std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aShape));
+
+ aPnt1 = aEdge->firstPoint();
+ aPnt2 = aEdge->lastPoint();
+
+ // Find the middle point
+ aP = gp_Pnt((aPnt1->x() + aPnt2->x())/2.,
+ (aPnt1->y() + aPnt2->y())/2.,
+ (aPnt1->z() + aPnt2->z())/2.);
- std::shared_ptr<GeomAPI_Pnt> aPnt1 = aEdge->firstPoint();
- std::shared_ptr<GeomAPI_Pnt> aPnt2 = aEdge->lastPoint();
+ } else {
+ double aMidParam = (aCurve->startParam() + aCurve->endParam()) / 2.;
+ std::shared_ptr<GeomAPI_Pnt> aPnt = aCurve->getPoint(aMidParam);
+ aP = aPnt->impl<gp_Pnt>();
- // Find the middle point
- gp_Pnt aP((aPnt1->x() + aPnt2->x())/2.,
- (aPnt1->y() + aPnt2->y())/2.,
- (aPnt1->z() + aPnt2->z())/2.);
+ aPnt1 = aCurve->getPoint((aMidParam + aCurve->endParam()) / 2.);
+ aPnt2 = aCurve->getPoint((aMidParam + aCurve->startParam()) / 2.);
+ }
+ aVec1 = gp_Vec(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
+ } else {
+ // This is a point
+ std::shared_ptr<GeomAPI_Vertex> aVertex = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aShape));
+ std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+ aP = aPnt->impl<gp_Pnt>();
- gp_Vec aVec1(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
+ std::shared_ptr<GeomAPI_Dir> aDir = thePrs->plane()->dirX();
+ aVec1 = gp_Vec(aDir->impl<gp_Dir>());
+ }
gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl<gp_Dir>());
aShift.Normalize();
aShift.Multiply(MyStep);
- int aPos = getPositionIndex(theLine, thePrs);
+ int aPos = getPositionIndex(theShape, thePrs);
int aM = 1;
if ((aPos % 2) == 0) {
// Even position
#include "SketcherPrs_PositionMgr.h"
#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Curve.h>
+#include <GeomAPI_Vertex.h>
#include <SketchPlugin_Constraint.h>
#include <SelectMgr_Selection.hxx>
#include <SelectMgr_EntityOwner.hxx>
+#include <GeomAdaptor_Curve.hxx>
+#include <BRep_Tool.hxx>
+#include <StdPrs_DeflectionCurve.hxx>
+#include <StdPrs_Point.hxx>
+#include <Geom_CartesianPoint.hxx>
+
extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
const std::string& theAttribute);
prepareAspect();
ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
- std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getLine(aObj1);
+ std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
if (aLine1.get() == NULL)
return;
void SketcherPrs_Rigid::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
{
- Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
-
- Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
- aGroup->SetPrimitivesAspect(aLineAspect);
+ ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+ std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
+ if (aShape.get() == NULL)
+ return;
- addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
+ Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
+ if (aShape->isEdge()) {
+ Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
+ aGroup->SetPrimitivesAspect(aLineAspect);
+ std::shared_ptr<GeomAPI_Curve> aCurve = std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(aShape));
+ if (aCurve->isLine()) {
+ addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
+ } else {
+ GeomAdaptor_Curve aAdaptor(aCurve->impl<Handle(Geom_Curve)>(), aCurve->startParam(), aCurve->endParam());
+ StdPrs_DeflectionCurve::Add(thePrs,aAdaptor,myDrawer);
+ }
+ } else {
+ // This is a point
+ Handle(Prs3d_PointAspect) aPntAspect = new Prs3d_PointAspect(Aspect_TOM_PLUS, theColor, 1);
+ myDrawer->SetPointAspect(aPntAspect);
+
+ std::shared_ptr<GeomAPI_Vertex> aVertex = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aShape));
+ std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+ Handle(Geom_CartesianPoint) aPoint = new Geom_CartesianPoint(aPnt->impl<gp_Pnt>());
+ StdPrs_Point::Add(thePrs, aPoint, myDrawer);
+ }
}
void SketcherPrs_SymbolPrs::addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const
{
ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, theAttrName);
- std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getLine(aObj);
+ std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aObj);
if (aLine.get() == NULL)
return;
std::shared_ptr<GeomAPI_Edge> aEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aLine));
}
-std::shared_ptr<GeomAPI_Shape> getLine(ObjectPtr theObject)
+std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject)
{
ResultConstructionPtr aRes = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theObject);
if (aRes.get() != NULL) {
ObjectPtr getResult(SketchPlugin_Constraint* theFeature,
const std::string& theAttrName);
- std::shared_ptr<GeomAPI_Shape> getLine(ObjectPtr theObject);
+ std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject);
std::shared_ptr<GeomAPI_Pnt2d> getPoint(SketchPlugin_Constraint* theFeature,
const std::string& theAttrName);