GeomAPI_Lin.h
GeomAPI_Lin2d.h
GeomAPI_Dir.h
+ GeomAPI_Dir2d.h
GeomAPI_Pln.h
GeomAPI_Shape.h
)
GeomAPI_Lin.cpp
GeomAPI_Lin2d.cpp
GeomAPI_Dir.cpp
+ GeomAPI_Dir2d.cpp
GeomAPI_Pln.cpp
GeomAPI_Shape.cpp
)
#include <GeomAPI_Circ2d.h>
#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Dir2d.h>
#include <gp_Dir2d.hxx>
#include <gp_Circ2d.hxx>
#define MY_CIRC2D static_cast<gp_Circ2d*>(myImpl)
+static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
+ const gp_Dir2d theDir, const double theRadius)
+{
+ gp_Pnt2d aCenter(theCenterX, theCenterY);
+ return new gp_Circ2d(gp_Ax2d(aCenter, theDir), theRadius);
+}
+
static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY,
const double thePointX, const double thePointY)
{
return NULL;
gp_Dir2d aDir(theCenterX - thePointX, theCenterY - thePointY);
- return new gp_Circ2d(gp_Ax2d(aCenter, aDir), aRadius);
+
+ return newCirc2d(theCenterX, theCenterY, aDir, aRadius);
}
-
GeomAPI_Circ2d::GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
const boost::shared_ptr<GeomAPI_Pnt2d>& theCirclePoint)
: GeomAPI_Interface(newCirc2d(theCenter->x(), theCenter->y(),
theCirclePoint->x(), theCirclePoint->y()))
{}
+GeomAPI_Circ2d::GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+ const boost::shared_ptr<GeomAPI_Dir2d>& theDir,
+ double theRadius)
+ : GeomAPI_Interface(newCirc2d(theCenter->x(), theCenter->y(),
+ theDir->impl<gp_Dir2d>(), theRadius))
+{
+
+}
+
const boost::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Circ2d::project(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
{
boost::shared_ptr<GeomAPI_Pnt2d> aResult;
#include <boost/shared_ptr.hpp>
class GeomAPI_Pnt2d;
+class GeomAPI_Dir2d;
/**\class GeomAPI_Circ2d
* \ingroup DataModel
GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
const boost::shared_ptr<GeomAPI_Pnt2d>& theCirclePoint);
+ /// Creation of circle defined by center point, direction and circle radius
+ GeomAPI_Circ2d(const boost::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+ const boost::shared_ptr<GeomAPI_Dir2d>& theDir,
+ double theRadius);
+
/// Project point on line
const boost::shared_ptr<GeomAPI_Pnt2d> project(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const;
};
--- /dev/null
+// File: GeomAPI_Dir2d.cpp
+// Created: 23 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#include <GeomAPI_Dir2d.h>
+#include <GeomAPI_XY.h>
+
+#include <gp_Dir2d.hxx>
+
+#define MY_DIR static_cast<gp_Dir2d*>(myImpl)
+
+GeomAPI_Dir2d::GeomAPI_Dir2d(const double theX, const double theY)
+ : GeomAPI_Interface(new gp_Dir2d(theX, theY))
+{}
+
+GeomAPI_Dir2d::GeomAPI_Dir2d(const boost::shared_ptr<GeomAPI_XY>& theCoords)
+ : GeomAPI_Interface(new gp_Dir2d(theCoords->x(), theCoords->y()))
+{}
+
+double GeomAPI_Dir2d::x() const
+{
+ return MY_DIR->X();
+}
+
+double GeomAPI_Dir2d::y() const
+{
+ return MY_DIR->Y();
+}
+
+const boost::shared_ptr<GeomAPI_XY> GeomAPI_Dir2d::xy()
+{
+ return boost::shared_ptr<GeomAPI_XY>(new GeomAPI_XY(MY_DIR->X(), MY_DIR->Y()));
+}
+
+double GeomAPI_Dir2d::dot(const boost::shared_ptr<GeomAPI_Dir2d>& theArg) const
+{
+ return MY_DIR->Dot(theArg->impl<gp_Dir2d>());
+}
+
+double GeomAPI_Dir2d::cross(const boost::shared_ptr<GeomAPI_Dir2d>& theArg) const
+{
+ return MY_DIR->XY().Crossed(theArg->impl<gp_Dir2d>().XY());
+}
+
--- /dev/null
+// File: GeomAPI_Dir2d.hxx
+// Created: 23 Apr 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef GeomAPI_Dir2d_HeaderFile
+#define GeomAPI_Dir2d_HeaderFile
+
+#include <GeomAPI_Interface.h>
+#include <boost/shared_ptr.hpp>
+
+class GeomAPI_XY;
+
+/**\class GeomAPI_Dir2d
+ * \ingroup DataModel
+ * \brief 2D direction defined by three normalized coordinates
+ */
+
+class GEOMAPI_EXPORT GeomAPI_Dir2d: public GeomAPI_Interface
+{
+public:
+ /// Creation of direction by coordinates
+ GeomAPI_Dir2d(const double theX, const double theY);
+ /// Creation of direction by coordinates
+ GeomAPI_Dir2d(const boost::shared_ptr<GeomAPI_XY>& theCoords);
+
+ /// returns X coordinate
+ double x() const;
+ /// returns Y coordinate
+ double y() const;
+
+ /// returns coordinates of the direction
+ const boost::shared_ptr<GeomAPI_XY> xy();
+
+ /// result is a scalar product of directions
+ double dot(const boost::shared_ptr<GeomAPI_Dir2d>& theArg) const;
+ /// result is a cross product of two directions
+ double cross(const boost::shared_ptr<GeomAPI_Dir2d>& theArg) const;
+};
+
+#endif
+
#include<GeomAPI_Pnt2d.h>
#include<GeomAPI_XY.h>
+#include<GeomAPI_XYZ.h>
+#include<GeomAPI_Pnt.h>
+#include<GeomAPI_Dir.h>
#include<gp_Pnt2d.hxx>
return MY_PNT2D->SetY(theY);
}
+boost::shared_ptr<GeomAPI_Pnt> GeomAPI_Pnt2d::to3D(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin,
+ const boost::shared_ptr<GeomAPI_Dir>& theDirX,
+ const boost::shared_ptr<GeomAPI_Dir>& theDirY)
+{
+ boost::shared_ptr<GeomAPI_XYZ> aSum = theOrigin->xyz()->added(
+ theDirX->xyz()->multiplied(x()))->added(theDirY->xyz()->multiplied(y()));
+
+ return boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
+}
+
const boost::shared_ptr<GeomAPI_XY> GeomAPI_Pnt2d::xy()
{
return boost::shared_ptr<GeomAPI_XY>(new GeomAPI_XY(MY_PNT2D->X(), MY_PNT2D->Y()));
#include <boost/shared_ptr.hpp>
class GeomAPI_XY;
+class GeomAPI_Pnt;
+class GeomAPI_Dir;
/**\class GeomAPI_Pnt2d
* \ingroup DataModel
/// sets Y coordinate
void setY(const double theY);
+ /// Returns the 3D point
+ boost::shared_ptr<GeomAPI_Pnt> to3D(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin,
+ const boost::shared_ptr<GeomAPI_Dir>& theDirX,
+ const boost::shared_ptr<GeomAPI_Dir>& theDirY);
+
/// returns coordinates of the point
const boost::shared_ptr<GeomAPI_XY> xy();
if (!theFeature || !theSketch)
return anAIS;
/*
- boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
- boost::shared_ptr<GeomDataAPI_Point> anOrigin =
- boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
- boost::shared_ptr<GeomDataAPI_Dir> aNormal =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
- gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0);
-
- aData = theFeature->data();
+ boost::shared_ptr<GeomAPI_Pln> aGPlane = PartSet_Tools::sketchPlane(theSketch);
+ gp_Pln aPlane = aGPlane->impl<gp_Pln>();
+
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
if (!anAttr)
#include <GeomDataAPI_Dir.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Lin2d.h>
+#include <GeomAPI_Pln.h>
#include <AIS_InteractiveObject.hxx>
#include <AIS_LengthDimension.hxx>
if (!theFeature || !theSketch)
return thePreviuos;
- boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
- boost::shared_ptr<GeomDataAPI_Point> anOrigin =
- boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
- boost::shared_ptr<GeomDataAPI_Dir> aNormal =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
- gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0/*D*/);
+ boost::shared_ptr<GeomAPI_Pln> aGPlane = PartSet_Tools::sketchPlane(theSketch);
+ gp_Pln aPlane = aGPlane->impl<gp_Pln>();
- aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
if (!anAttr)
boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
double aFlyout = aFlyoutAttr->value();
+ boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+ double aValue = aValueAttr->value();
+
aData = aFeature->data();
if (!aData->isValid())
return thePreviuos;
if (anAIS.IsNull())
{
Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension (aP1, aP2, aPlane);
+ aDimAIS->SetCustomValue(aValue);
Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
anAspect->MakeArrows3d (Standard_False);
Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS);
if (!aDimAIS.IsNull()) {
aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane);
+ aDimAIS->SetCustomValue(aValue);
aDimAIS->SetFlyout(aFlyout);
aDimAIS->Redisplay(Standard_True);
#include <PartSet_ConstraintRadiusPrs.h>
#include <PartSet_Tools.h>
-#include <PartSet_FeatureLinePrs.h>
+#include <PartSet_FeatureCirclePrs.h>
+#include <PartSet_FeatureArcPrs.h>
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_ConstraintRadius.h>
+#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Dir.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Lin2d.h>
+#include <GeomAPI_Pln.h>
+#include <GeomAPI_Dir.h>
+
+#include <GeomAlgoAPI_EdgeBuilder.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeDouble.h>
#include <AIS_InteractiveObject.hxx>
+#include <AIS_RadiusDimension.hxx>
#include <Precision.hxx>
+#include <gp_Circ.hxx>
+#include <V3d_View.hxx>
using namespace std;
bool PartSet_ConstraintRadiusPrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode)
{
bool aResult = false;
- if (feature() && theMode == SM_FirstPoint &&
- (theFeature && theFeature->getKind() == SKETCH_CIRCLE_KIND ||
- theFeature && theFeature->getKind() == SKETCH_ARC_KIND)) {
+ if (!feature() || theMode != SM_FirstPoint || !theFeature) {
+ return aResult;
+ }
+ std::string aKind = theFeature->getKind();
+ if (aKind == SKETCH_CIRCLE_KIND || aKind == SKETCH_ARC_KIND) {
// set length feature
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
aRef->setFeature(theFeature);
- // set length value
- /*aData = theFeature->data();
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
- boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
-
- double aLenght = aPoint1->pnt()->distance(aPoint2->pnt());
- */
- double aLenght = 50;
- PartSet_Tools::setFeatureValue(feature(), aLenght, CONSTRAINT_ATTR_VALUE);
+ double aLength = 50;
+ bool isValid;
+ if (aKind == SKETCH_CIRCLE_KIND) {
+ aLength = PartSet_Tools::featureValue(theFeature, CIRCLE_ATTR_RADIUS, isValid);
+ }
+ else if (aKind == SKETCH_ARC_KIND) {
+ boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->data()->attribute(ARC_ATTR_CENTER));
+ boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->data()->attribute(ARC_ATTR_START));
+ aLength = aCenterAttr->pnt()->distance(aStartAttr->pnt());
+ }
+
+ PartSet_Tools::setFeatureValue(feature(), aLength, CONSTRAINT_ATTR_VALUE);
aResult = true;
}
return aResult;
{
case SM_SecondPoint: {
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
- /*boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
- FeaturePtr aFeature;
- if (anAttr) {
- aFeature = anAttr->feature();
- if (aFeature->getKind() != SKETCH_LINE_KIND) {
- aFeature = FeaturePtr();
- }
- }
+
boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>
(new GeomAPI_Pnt2d(theX, theY));
- boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = PartSet_FeatureLinePrs::createLin2d(aFeature);
- boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aPoint);
- double aDistance = aPoint->distance(aResult);
- double aStartX, aStartY;
- PartSet_FeatureLinePrs::getLinePoint(aFeature, LINE_ATTR_START, aStartX, aStartY);
+ PartSet_Tools::setFeaturePoint(feature(), theX, theY, SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT);
- if (!aFeatureLin->isRight(aPoint))
- aDistance = -aDistance;
- */
- double aDistance = 40;
- AttributeDoublePtr aFlyoutAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
- aFlyoutAttr->setValue(aDistance);
+ //double aDistance = 40;
+ //AttributeDoublePtr aFlyoutAttr =
+ // boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
+ //aFlyoutAttr->setValue(aDistance);
aMode = SM_DonePoint;
}
Handle(AIS_InteractiveObject) anAIS = thePreviuos;
if (!theFeature || !theSketch)
return anAIS;
- /*
- boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
- boost::shared_ptr<GeomDataAPI_Point> anOrigin =
- boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
- boost::shared_ptr<GeomDataAPI_Dir> aNormal =
- boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
- gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0);
-
- aData = theFeature->data();
+
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
if (!anAttr)
- return thePreviuos;
+ return anAIS;
FeaturePtr aFeature = anAttr->feature();
- if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND)
- return thePreviuos;
-
- boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
- double aFlyout = aFlyoutAttr->value();
-
- aData = aFeature->data();
- if (!aData->isValid())
- return thePreviuos;
-
- boost::shared_ptr<GeomDataAPI_Point2D> aPointStart =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
- boost::shared_ptr<GeomDataAPI_Point2D> aPointEnd =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
-
- gp_Pnt aPoint1, aPoint2;
- PartSet_Tools::convertTo3D(aPointStart->x(), aPointStart->y(), theSketch, aPoint1);
- PartSet_Tools::convertTo3D(aPointEnd->x(), aPointEnd->y(), theSketch, aPoint2);
-
- //Build dimension here
- gp_Pnt aP1 = aPoint1;
- gp_Pnt aP2 = aPoint2;
- if (aFlyout < 0) {
- aP1 = aPoint2;
- aP2 = aPoint1;
- }
+ if (!aFeature || aFeature->getKind() != SKETCH_CIRCLE_KIND)
+ return anAIS;
- Handle(AIS_InteractiveObject) anAIS = thePreviuos;
+
+ //boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr =
+ // boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
+ //double aFlyout = aFlyoutAttr->value();
+ boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+ double aValue = aValueAttr->value();
+
+ gp_Circ aCircle;
+ gp_Pnt anAnchorPoint;
+ double aRadius;
+ //boost::shared_ptr<GeomAPI_Shape> aShape;
+ if (aFeature->getKind() == SKETCH_CIRCLE_KIND) {
+ boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
+ // a circle
+ boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CIRCLE_ATTR_CENTER));
+ boost::shared_ptr<GeomAPI_Pnt2d> aCenter2D = aCenterAttr->pnt();
+
+ boost::shared_ptr<GeomAPI_Pnt> aCenter = PartSet_Tools::point3D(aCenter2D, theSketch);
+
+ boost::shared_ptr<GeomDataAPI_Dir> aNDir =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(theSketch->data()->attribute(SKETCH_ATTR_NORM));
+ boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
+ const gp_Dir& aDir = aNormal->impl<gp_Dir>();
+ bool isValid;
+ aRadius = PartSet_Tools::featureValue(aFeature, CIRCLE_ATTR_RADIUS, isValid);
+ aCircle = gp_Circ(gp_Ax2(aCenter->impl<gp_Pnt>(), aDir), aRadius);
+
+ // an anchor point
+ boost::shared_ptr<GeomDataAPI_Point2D> aAnchorAttr =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->data()->attribute
+ (SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT));
+ boost::shared_ptr<GeomAPI_Pnt2d> anAnchor2D = aAnchorAttr->pnt();
+ boost::shared_ptr<GeomAPI_Pnt> anAnchor = PartSet_Tools::point3D(anAnchor2D, theSketch);
+ anAnchorPoint = anAnchor->impl<gp_Pnt>();
+
+ //aShape = GeomAlgoAPI_EdgeBuilder::line(aCenter, anAnchor);
+ //boost::shared_ptr<GeomAPI_Pnt> theStart, boost::shared_ptr<GeomAPI_Pnt> theEnd)
+ }
if (anAIS.IsNull())
{
- Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension (aP1, aP2, aPlane);
+ Handle(AIS_RadiusDimension) aDimAIS = new AIS_RadiusDimension(aCircle, anAnchorPoint);
+ aDimAIS->SetCustomValue(aValue);
+ //Handle(AIS_RadiusDimension) aDimAIS = new AIS_RadiusDimension(aShape->impl<TopoDS_Shape>());
Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
anAspect->MakeArrows3d (Standard_False);
anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
anAspect->MakeTextShaded(false);
aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false);
- //if (isUnitsDisplayed)
- //{
- // aDimAIS->SetDisplayUnits (aDimDlg->GetUnits ());
- //}
aDimAIS->SetDimensionAspect (anAspect);
- aDimAIS->SetFlyout(aFlyout);
+ //aDimAIS->SetFlyout(aFlyout);
aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE);
anAIS = aDimAIS;
}
else {
// update presentation
- Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS);
+ Handle(AIS_RadiusDimension) aDimAIS = Handle(AIS_RadiusDimension)::DownCast(anAIS);
if (!aDimAIS.IsNull()) {
- aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane);
- aDimAIS->SetFlyout(aFlyout);
+ gp_Pnt anAPoint(anAnchorPoint.X(),anAnchorPoint.Y(),anAnchorPoint.Z());
+ aDimAIS->SetMeasuredGeometry(aCircle, anAnchorPoint);
+ aDimAIS->SetCustomValue(aValue);
+ //aDimAIS->SetMeasuredGeometry(aShape->impl<TopoDS_Shape>());
+ //aDimAIS->SetFlyout(aFlyout);
aDimAIS->Redisplay(Standard_True);
}
}
-*/
return anAIS;
}
+void PartSet_ConstraintRadiusPrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch,
+ gp_Pnt& thePoint, Handle(V3d_View) theView,
+ double& theX, double& theY)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ if (!anAttr)
+ return;
+ FeaturePtr aFeature = anAttr->feature();
+ if (!aFeature)
+ return;
+
+ gp_Circ aCircle;
+ gp_Pnt anAnchorPoint;
+ if (aFeature->getKind() == SKETCH_CIRCLE_KIND) {
+ PartSet_FeatureCirclePrs::projectPointOnFeature(aFeature, theSketch, thePoint, theView, theX, theY);
+ }
+ else if (aFeature->getKind() == SKETCH_ARC_KIND) {
+ PartSet_FeatureArcPrs::projectPointOnFeature(aFeature, theSketch, thePoint, theView, theX, theY);
+ }
+ // TODO: a bug in AIS_RadiusDimension:
+ // The anchor point can't be myCirc.Location() - an exception is raised.
+ // But we need exactly this case...
+ // We want to show a radius dimension starting from the circle centre and
+ // ending at the user-defined point.
+ // Also, if anchor point coincides with myP2, the radius dimension is not displayed at all.
+ double aDelta = 1/1000.0;
+ theX += aDelta;
+ theY += aDelta;
+}
+
std::string PartSet_ConstraintRadiusPrs::getAttribute(const PartSet_SelectionMode& theMode) const
{
return "";
#include "PartSet_FeaturePrs.h"
#include "PartSet_Constants.h"
+#include <gp_Pnt.hxx>
+
class GeomDataAPI_Point2D;
class Handle_AIS_InteractiveObject;
+class Handle_V3d_View;
/*!
\class PartSet_ConstraintRadiusPrs
/// \param theY the vertical point coordinate
virtual boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
double theY);
+ /// Project the view point on the feature. The output coordinates belong to the feature
+ /// \param theFeature a feature
+ /// \param theSketch the sketch feature
+ /// \param thePoint a viewer point
+ /// \param theView the OCC view
+ /// \theX the output horizontal coordinate of a projected point
+ /// \theY the output vertical coordinate of a projected point
+ static void projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, gp_Pnt& thePoint,
+ Handle_V3d_View theView, double& theX, double& theY);
+
protected:
/// Returns the feature point in the selection mode position.
/// \param theMode the current operation selection mode. The feature attribute depends on the mode
return aPoint2D;
}
-void PartSet_FeatureArcPrs::projectPointOnArc(gp_Pnt& thePoint, Handle(V3d_View) theView,
- double& theX, double& theY)
+void PartSet_FeatureArcPrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch,
+ gp_Pnt& thePoint, Handle(V3d_View) theView,
+ double& theX, double& theY)
{
- FeaturePtr aSketch = sketch();
+ FeaturePtr aSketch = theSketch;
if (aSketch) {
double aX, anY;
PartSet_Tools::convertTo2D(thePoint, aSketch, theView, aX, anY);
// circle origin point and radius
- boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
boost::shared_ptr<GeomDataAPI_Point2D> aCenter = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
(aData->attribute(ARC_ATTR_CENTER));
boost::shared_ptr<GeomDataAPI_Point2D> aStart = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
/// \return next attribute selection mode
virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
- void projectPointOnArc(gp_Pnt& thePoint, Handle_V3d_View theView,
- double& theX, double& theY);
+ /// Project the view point on the feature. The output coordinates belong to the feature
+ /// \param theFeature a feature
+ /// \param theSketch the sketch feature
+ /// \param thePoint a viewer point
+ /// \param theView the OCC view
+ /// \theX the output horizontal coordinate of a projected point
+ /// \theY the output vertical coordinate of a projected point
+ static void projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, gp_Pnt& thePoint,
+ Handle_V3d_View theView, double& theX, double& theY);
/// \brief Move the full feature.
/// \param theDeltaX the delta for X coordinate is moved
#include <SketchPlugin_Circle.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Dir.h>
#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Circ2d.h>
+#include <GeomAPI_Dir2d.h>
+#include <GeomAPI_Dir.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefList.h>
+#include <V3d_View.hxx>
#include <Precision.hxx>
using namespace std;
return aPoint2D;
}
+void PartSet_FeatureCirclePrs::projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch,
+ gp_Pnt& thePoint, Handle(V3d_View) theView,
+ double& theX, double& theY)
+{
+ FeaturePtr aSketch = theSketch;
+ if (aSketch) {
+ double aX, anY;
+ PartSet_Tools::convertTo2D(thePoint, aSketch, theView, aX, anY);
+
+ // circle origin point and radius
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aCenter = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aData->attribute(CIRCLE_ATTR_CENTER));
+ bool isValid;
+ double aRadius = PartSet_Tools::featureValue(theFeature, CIRCLE_ATTR_RADIUS, isValid);
+
+ boost::shared_ptr<GeomAPI_Dir2d> aNormal(new GeomAPI_Dir2d(aX, anY));
+ boost::shared_ptr<GeomAPI_Circ2d> aCirc(new GeomAPI_Circ2d(aCenter->pnt(), aNormal, aRadius));
+ boost::shared_ptr<GeomAPI_Pnt2d> aGeomPoint2d(new GeomAPI_Pnt2d(aX, anY));
+ boost::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aCirc->project(aGeomPoint2d);
+ if (aPnt2d) {
+ theX = aPnt2d->x();
+ theY = aPnt2d->y();
+ }
+ }
+}
+
boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::featurePoint
(const PartSet_SelectionMode& theMode)
{
#include "PartSet_FeaturePrs.h"
#include "PartSet_Constants.h"
+#include <gp_Pnt.hxx>
+
class GeomDataAPI_Point2D;
+class Handle_V3d_View;
/*!
\class PartSet_FeatureCirclePrs
/// \param theY the vertical point coordinate
virtual boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
double theY);
+ /// Project the view point on the feature. The output coordinates belong to the feature
+ /// \param theFeature a feature
+ /// \param theSketch the sketch feature
+ /// \param thePoint a viewer point
+ /// \param theView the OCC view
+ /// \theX the output horizontal coordinate of a projected point
+ /// \theY the output vertical coordinate of a projected point
+ static void projectPointOnFeature(FeaturePtr theFeature, FeaturePtr theSketch, gp_Pnt& thePoint,
+ Handle_V3d_View theView, double& theX, double& theY);
+
protected:
/// Returns the feature point in the selection mode position.
/// \param theMode the current operation selection mode. The feature attribute depends on the mode
PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
// show value edit dialog
- double aValue;
- if (PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, aValue)) {
+ bool isValid;
+ double aValue = PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, isValid);
+ if (isValid) {
showEditor(theEvent, aValue);
setPointSelectionMode(SM_ThirdPoint/*aMode*/);
}
double aX, anY;
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
- /*if (myPointSelectionMode == SM_ThirdPoint) {
- if (feature()->getKind() == SKETCH_ARC_KIND) {
- boost::shared_ptr<PartSet_FeatureArcPrs> anArcPrs =
- boost::dynamic_pointer_cast<PartSet_FeatureArcPrs>(myFeaturePrs);
- if (anArcPrs) {
- anArcPrs->projectPointOnArc(aPoint, theView, aX, anY);
- }
+ if (feature()->getKind() == PartSet_ConstraintRadiusPrs::getKind()) {
+ boost::shared_ptr<PartSet_ConstraintRadiusPrs> anArcPrs =
+ boost::dynamic_pointer_cast<PartSet_ConstraintRadiusPrs>(myFeaturePrs);
+ if (anArcPrs) {
+ anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY);
}
- }*/
+ }
myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
flushUpdated();
boost::shared_ptr<PartSet_FeatureArcPrs> anArcPrs =
boost::dynamic_pointer_cast<PartSet_FeatureArcPrs>(myFeaturePrs);
if (anArcPrs) {
- anArcPrs->projectPointOnArc(aPoint, theView, aX, anY);
+ anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY);
}
}
PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
boost::shared_ptr<PartSet_FeatureArcPrs> anArcPrs =
boost::dynamic_pointer_cast<PartSet_FeatureArcPrs>(myFeaturePrs);
if (anArcPrs) {
- anArcPrs->projectPointOnArc(aPoint, theView, aX, anY);
+ anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY);
}
}
}
{
// changed
if (!theSelected.empty()) {
-
- double aValue;
- if(PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, aValue)) {
+ bool isValid;
+ double aValue = PartSet_Tools::featureValue(feature(), CONSTRAINT_ATTR_VALUE, isValid);
+ if (isValid) {
QPoint aPos = theEvent->globalPos();
myEditor->start(aPos, aValue);
}
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Dir.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Pln.h>
+#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Pnt.h>
#include <GeomAPI_Dir.h>
#include <GeomAPI_XYZ.h>
anAttribute->setValue(theValue);
}
-bool PartSet_Tools::featureValue(FeaturePtr theFeature, const std::string& theAttribute,
- double& theValue)
+double PartSet_Tools::featureValue(FeaturePtr theFeature, const std::string& theAttribute,
+ bool& isValid)
{
- bool aResult = false;
- if (!theFeature)
- return aResult;
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
- AttributeDoublePtr anAttribute =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(theAttribute));
- if (anAttribute) {
- theValue = anAttribute->value();
- aResult = true;
+ isValid = false;
+ double aValue;
+ if (theFeature) {
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ AttributeDoublePtr anAttribute =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(theAttribute));
+ if (anAttribute) {
+ aValue = anAttribute->value();
+ isValid = true;
+ }
}
- return aResult;
+ return aValue;
}
void PartSet_Tools::createConstraint(FeaturePtr theSketch,
return aPoint2D;
}
+
+boost::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(FeaturePtr theSketch)
+{
+ boost::shared_ptr<GeomAPI_Pln> aPlane;
+ double aA, aB, aC, aD;
+
+ boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
+ boost::shared_ptr<GeomDataAPI_Point> anOrigin =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+ boost::shared_ptr<GeomDataAPI_Dir> aNormal =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+ aA = aNormal->x();
+ aB = aNormal->y();
+ aC = aNormal->z();
+ aD = 0;
+
+ aPlane = boost::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
+ return aPlane;
+}
+
+boost::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(
+ boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
+ FeaturePtr theSketch)
+{
+ boost::shared_ptr<GeomAPI_Pnt> aPoint;
+ if (!theSketch || !thePoint2D)
+ return aPoint;
+
+ boost::shared_ptr<GeomDataAPI_Point> aC =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(theSketch->data()->attribute(SKETCH_ATTR_ORIGIN));
+ boost::shared_ptr<GeomDataAPI_Dir> aX =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(theSketch->data()->attribute(SKETCH_ATTR_DIRX));
+ boost::shared_ptr<GeomDataAPI_Dir> aY =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(theSketch->data()->attribute(SKETCH_ATTR_DIRY));
+
+ return thePoint2D->to3D(aC->pnt(), aX->dir(), aY->dir());
+}
class Handle_V3d_View;
class XGUI_ViewerPrs;
class GeomDataAPI_Point2D;
+class GeomAPI_Pln;
+class GeomAPI_Pnt2d;
+class GeomAPI_Pnt;
class PartSet_FeaturePrs;
/*!
/// \brief Returns the feature double value if it is.
/// \param theFeature the feature
/// \param theAttribute the feature attribute
- /// \param theValue the horizontal coordinate
- /// \returns the state whether the value is correct
- static bool featureValue(FeaturePtr theFeature, const std::string& theAttribute,
- double& theValue);
+ /// \param isValid an output parameter whether the value is valid
+ /// \returns the feature value
+ static double featureValue(FeaturePtr theFeature, const std::string& theAttribute,
+ bool& isValid);
/// Creates a constraint on two points
/// \param thePoint1 the first point
static boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
double theY);
+ /// Create a sketch plane instance
+ /// \param theSketch a sketch feature
+ /// \return API object of geom plane
+ static boost::shared_ptr<GeomAPI_Pln> sketchPlane(FeaturePtr theSketch);
+
+ /// Create a point 3D on a basis of point 2D and sketch feature
+ /// \param thePoint2D a point on a sketch
+ /// \param theSketch a sketch feature
+ /// \return API object of point 3D
+ static boost::shared_ptr<GeomAPI_Pnt> point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
+ FeaturePtr theSketch);
private:
/// Return the distance between the feature and the point
/// \param theFeature feature object