#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Line.h>
+#include <SketcherPrs_Tools.h>
+#include <SketcherPrs_Factory.h>
+
#include <GeomAPI_Lin2d.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomDataAPI_Point2D.h>
const double tolerance = 1e-7;
+
SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance()
{
}
return false;
DataPtr aData = data();
- std::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint_A = SketcherPrs_Tools::getFeaturePoint(
aData, SketchPlugin_Constraint::ENTITY_A());
- std::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint_B = SketcherPrs_Tools::getFeaturePoint(
aData, SketchPlugin_Constraint::ENTITY_B());
std::shared_ptr<GeomAPI_Pnt2d> aPnt_A;
aPnt_A = aPoint_A->pnt();
aPnt_B = aPoint_B->pnt();
} else if (!aPoint_A && aPoint_B) {
- std::shared_ptr<SketchPlugin_Line> aLine = getFeatureLine(
+ std::shared_ptr<SketchPlugin_Line> aLine = SketcherPrs_Tools::getFeatureLine(
aData, SketchPlugin_Constraint::ENTITY_A());
if (aLine) {
aPnt_B = aPoint_B->pnt();
- aPnt_A = getProjectionPoint(aLine, aPnt_B);
+ aPnt_A = SketcherPrs_Tools::getProjectionPoint(aLine, aPnt_B);
}
} else if (aPoint_A && !aPoint_B) {
- std::shared_ptr<SketchPlugin_Line> aLine = getFeatureLine(
+ std::shared_ptr<SketchPlugin_Line> aLine = SketcherPrs_Tools::getFeatureLine(
aData, SketchPlugin_Constraint::ENTITY_B());
if (aLine) {
aPnt_A = aPoint_A->pnt();
- aPnt_B = getProjectionPoint(aLine, aPnt_A);
+ aPnt_B = SketcherPrs_Tools::getProjectionPoint(aLine, aPnt_A);
}
}
if (!aPnt_A || !aPnt_B)
if (!sketch())
return thePrevious;
- std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
-
- DataPtr aData = data();
- std::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(
- aData, SketchPlugin_Constraint::ENTITY_A());
- std::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(
- aData, SketchPlugin_Constraint::ENTITY_B());
-
- std::shared_ptr<GeomAPI_Pnt2d> aPnt_A;
- std::shared_ptr<GeomAPI_Pnt2d> aPnt_B;
-
- if (aPoint_A && aPoint_B) {
- aPnt_A = aPoint_A->pnt();
- aPnt_B = aPoint_B->pnt();
- } else if (!aPoint_A && aPoint_B) {
- std::shared_ptr<SketchPlugin_Line> aLine = getFeatureLine(
- aData, SketchPlugin_Constraint::ENTITY_A());
- if (aLine) {
- aPnt_B = aPoint_B->pnt();
- aPnt_A = getProjectionPoint(aLine, aPnt_B);
- }
- } else if (aPoint_A && !aPoint_B) {
- std::shared_ptr<SketchPlugin_Line> aLine = getFeatureLine(
- aData, SketchPlugin_Constraint::ENTITY_B());
- if (aLine) {
- aPnt_A = aPoint_A->pnt();
- aPnt_B = getProjectionPoint(aLine, aPnt_A);
- }
- }
- if (!aPnt_A || !aPnt_B)
- return AISObjectPtr();
-
- std::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
-
- std::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aPnt_A->x(), aPnt_A->y());
- std::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(aPnt_B->x(), aPnt_B->y());
- if(!aFlyOutAttr->isInitialized())
- return AISObjectPtr();
- std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y()/*aFPnt->x(), aFPnt->y()*/);
-
- // value calculation
- std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
- ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE()));
- double aValue = 0;
- // Issue #196: checking the positivity of the distance constraint
- // there is a validator for a distance constraint, that the value should be positive
- // in case if an invalid value is set, the current distance value is shown
- if (aValueAttr->isInitialized())
- aValue = aValueAttr->value();
-
AISObjectPtr anAIS = thePrevious;
- if (!anAIS)
- anAIS = AISObjectPtr(new GeomAPI_AISObject);
- anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue);
+ if (!anAIS) {
+ anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane());
+ }
// Set color from preferences
std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color",
std::shared_ptr<ModelAPI_Data> aData = data();
std::shared_ptr<GeomDataAPI_Point2D> aPointA =
- getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A());
+ SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_A());
std::shared_ptr<GeomDataAPI_Point2D> aPointB =
- getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B());
+ SketcherPrs_Tools::getFeaturePoint(aData, SketchPlugin_Constraint::ENTITY_B());
if (aPointA && aPointB) { // both points
aDistance = aPointA->pnt()->distance(aPointB->pnt());
} else {
if (!aPointA && aPointB) { //Line and point
std::shared_ptr<SketchPlugin_Line> aLine =
- getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A());
+ SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A());
if (aLine) {
aDistance = aLine->distanceToPoint(aPointB->pnt());
}
} else if (aPointA && !aPointB) { // Point and line
std::shared_ptr<SketchPlugin_Line> aLine =
- getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B());
+ SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B());
if (aLine) {
aDistance = aLine->distanceToPoint(aPointA->pnt());
}
}
}
-//*************************************************************************************
-std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
- const std::string& theAttribute)
-{
- std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
-
- if (!theData)
- return aPointAttr;
-
- FeaturePtr aFeature;
- std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
- ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
- if (anAttr)
- aFeature = ModelAPI_Feature::feature(anAttr->object());
-
- if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
- aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
- else if (aFeature && aFeature->getKind() == SketchPlugin_Circle::ID())
- aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
- else if (anAttr->attr()) {
- aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
- }
- return aPointAttr;
-}
-
-//*************************************************************************************
-std::shared_ptr<SketchPlugin_Line> getFeatureLine(DataPtr theData,
- const std::string& theAttribute)
-{
- std::shared_ptr<SketchPlugin_Line> aLine;
- if (!theData)
- return aLine;
-
- std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
- ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
- if (anAttr) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object());
- if (aFeature && aFeature->getKind() == SketchPlugin_Line::ID()) {
- aLine = std::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
- }
- }
- return aLine;
-}
-
-//*************************************************************************************
-std::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(
- const std::shared_ptr<SketchPlugin_Line>& theLine,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
- std::shared_ptr<ModelAPI_Data> aData = theLine->data();
- std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aData->attribute(SketchPlugin_Line::START_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aData->attribute(SketchPlugin_Line::END_ID()));
-
- GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y());
- return aLin2d.project(thePoint);
-}
SketchPlugin_ConstraintDistance();
};
-/// Obtain the point object from specified constraint parameter
-std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
- const std::string& theAttribute);
-
-std::shared_ptr<SketchPlugin_Line> getFeatureLine(DataPtr theData,
- const std::string& theAttribute);
-
-std::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(
- const std::shared_ptr<SketchPlugin_Line>& theLine,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
-
#endif
#include <GeomDataAPI_Point2D.h>
+#include <SketcherPrs_Factory.h>
+
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Result.h>
AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePrevious)
{
- std::shared_ptr<GeomAPI_Pnt> aPoint1, aPoint2;
- std::shared_ptr<GeomDataAPI_Point2D> aStartPoint, anEndPoint;
- if (!getPoints(aPoint1, aPoint2, aStartPoint, anEndPoint))
- return thePrevious; // not possible to show length because points are not defined
-
- AttributePtr aFlyOutAttribute = data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
- if (!aFlyOutAttribute->isInitialized()) {
- return thePrevious; // not possible to show length because points are not defined
- }
- std::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(aFlyOutAttribute);
- std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y());
- // value calculation
- // TODO: has to be calculated on definition of reference object
- double aDistance = aPoint1->distance(aPoint2);
- std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
- ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
- double aValue = aDistance;
- if (aValueAttr->isInitialized())
- aValue = aValueAttr->value();
- else
- aValueAttr->setValue(aValue);
- // End TODO
+ if (!sketch())
+ return thePrevious;
AISObjectPtr anAIS = thePrevious;
- if (!anAIS)
- anAIS = AISObjectPtr(new GeomAPI_AISObject);
- std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
- anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue);
+ if (!anAIS) {
+ anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane());
+ }
// Set color from preferences
std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color",
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Point.h>
+#include <SketcherPrs_Factory.h>
+
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePrevious)
{
- std::shared_ptr<ModelAPI_Feature> aCyrcFeature;
- double aRadius = circleRadius(aCyrcFeature);
- if (aRadius < 0)
- return thePrevious; // can not create a good presentation
-
- // Flyout point
- std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
- if (!aFlyoutAttr->isInitialized())
- return thePrevious; // can not create a good presentation
- std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
+ if (!sketch())
+ return thePrevious;
- // Prepare a circle
- std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
- if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle
- aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
- } else { // arc
- aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()));
- }
- std::shared_ptr<GeomAPI_Pnt> aCenter = sketch()->to3D(aCenterAttr->x(), aCenterAttr->y());
- std::shared_ptr<GeomDataAPI_Dir> aNDir = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- sketch()->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- std::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
- std::shared_ptr<GeomAPI_Circ> aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius));
-
- // Value
- std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
- ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
- if (aValueAttr->isInitialized())
- aRadius = aValueAttr->value();
AISObjectPtr anAIS = thePrevious;
- if (!anAIS)
- anAIS = AISObjectPtr(new GeomAPI_AISObject);
- anAIS->createRadius(aCircle, aFlyoutPnt, aRadius);
+ if (!anAIS) {
+ anAIS = SketcherPrs_Factory::radiusConstraint(this, sketch()->coordinatePlane());
+ }
// Set color from preferences
std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color",
#include "SketchPlugin_Line.h"
#include "SketchPlugin_Arc.h"
+#include "SketcherPrs_Tools.h"
+
#include <ModelAPI_Data.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_AttributeDouble.h>
#include <GeomDataAPI_Point2D.h>
+
bool SketchPlugin_DistanceAttrValidator::isValid(
const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
{
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
// If it is a line then we have to check that first attribute id not a line
- std::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(aFeature->data(), aParamA);
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint = SketcherPrs_Tools::getFeaturePoint(aFeature->data(), aParamA);
if (aPoint)
return true;
}
SketcherPrs_Equal.h
SketcherPrs_Tangent.h
SketcherPrs_SensitivePoint.h
+ SketcherPrs_Radius.h
+ SketcherPrs_LengthDimension.h
)
SET(PROJECT_SOURCES
SketcherPrs_Equal.cpp
SketcherPrs_Tangent.cpp
SketcherPrs_SensitivePoint.cpp
+ SketcherPrs_Radius.cpp
+ SketcherPrs_LengthDimension.cpp
)
SET(PROJECT_LIBRARIES
#include "SketcherPrs_HVDirection.h"
#include "SketcherPrs_Equal.h"
#include "SketcherPrs_Tangent.h"
+#include "SketcherPrs_Radius.h"
+#include "SketcherPrs_LengthDimension.h"
#define CONSTRAINT_PRS_IMPL(NAME, CLASS) \
AISObjectPtr SketcherPrs_Factory::NAME(SketchPlugin_Constraint* theConstraint, \
CONSTRAINT_PRS_IMPL(rigidConstraint, SketcherPrs_Rigid);
CONSTRAINT_PRS_IMPL(equalConstraint, SketcherPrs_Equal);
CONSTRAINT_PRS_IMPL(tangentConstraint, SketcherPrs_Tangent);
+CONSTRAINT_PRS_IMPL(radiusConstraint, SketcherPrs_Radius);
+CONSTRAINT_PRS_IMPL(lengthDimensionConstraint, SketcherPrs_LengthDimension);
AISObjectPtr SketcherPrs_Factory::horisontalConstraint(SketchPlugin_Constraint* theConstraint,
/// \param theConstraint the constraint
/// \param thePlane the current sketch plane
GET_CONSTRAINT_PRS(tangentConstraint)
+
+ /// Creates coincedent perpendicular presentation
+ /// \param theConstraint the constraint
+ /// \param thePlane the current sketch plane
+ GET_CONSTRAINT_PRS(radiusConstraint)
+
+ /// Creates coincedent perpendicular presentation
+ /// \param theConstraint the constraint
+ /// \param thePlane the current sketch plane
+ GET_CONSTRAINT_PRS(lengthDimensionConstraint)
};
#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_LengthDimension.cpp
+// Created: 27 March 2015
+// Author: Vitaly SMETANNIKOV
+
+#include "SketcherPrs_LengthDimension.h"
+#include "SketcherPrs_Tools.h"
+
+#include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_ConstraintLength.h>
+#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Circle.h>
+
+#include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_XYZ.h>
+#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Lin2d.h>
+
+#include <ModelAPI_Data.h>
+
+
+const int CONSTRAINT_TEXT_HEIGHT = 20; /// the text height of the constraint
+const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection tolerance
+
+
+static const gp_Pnt MyDefStart(0,0,0);
+static const gp_Pnt MyDefEnd(1,0,0);
+static const gp_Pln MyDefPln(gp_Pnt(0,0,0), gp_Dir(0,0,1));
+
+
+
+
+IMPLEMENT_STANDARD_HANDLE(SketcherPrs_LengthDimension, AIS_LengthDimension);
+IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_LengthDimension, AIS_LengthDimension);
+
+SketcherPrs_LengthDimension::SketcherPrs_LengthDimension(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+: AIS_LengthDimension(MyDefStart, MyDefEnd, MyDefPln),
+myConstraint(theConstraint), myPlane(thePlane)
+{
+ myAspect = new Prs3d_DimensionAspect();
+ myAspect->MakeArrows3d(false);
+ myAspect->MakeText3d(false);
+ myAspect->MakeTextShaded(false);
+ myAspect->MakeUnitsDisplayed(false);
+
+ SetDimensionAspect(myAspect);
+ SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE);
+}
+
+
+void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
+{
+ gp_Pnt aPnt1, aPnt2;
+ if (!getPoints(aPnt1, aPnt2))
+ return;
+ DataPtr aData = myConstraint->data();
+
+ AttributePtr aFlyOutAttribute = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
+ if (!aFlyOutAttribute->isInitialized()) {
+ return; // not possible to show length because points are not defined
+ }
+ std::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFlyOutAttribute);
+ std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = myPlane->to3D(aFlyOutAttr->x(), aFlyOutAttr->y());
+ gp_Pnt aFlyPnt = aFlyoutPnt->impl<gp_Pnt>();
+
+ double aDistance = aPnt1.Distance(aPnt2);
+
+ double aFlyout = 0;
+ double aDist = 0.0;
+ if (aDistance < Precision::Confusion())
+ aDist = aPnt1.Distance(aFlyPnt);
+ else {
+ gp_Lin aLine(aPnt1, gp_Vec(aPnt1, aPnt2));
+ aDist = aLine.Distance(aFlyPnt);
+ }
+
+ gp_XYZ aLineDir = aPnt2.XYZ().Subtracted(aPnt1.XYZ());
+ gp_XYZ aFOutDir = aFlyPnt.XYZ().Subtracted(aPnt1.XYZ());
+ gp_XYZ aNorm = myPlane->norm()->xyz()->impl<gp_XYZ>();
+ if (aLineDir.Crossed(aFOutDir).Dot(aNorm) < 0)
+ aDist = -aDist;
+ aFlyout = aDist;
+
+ SetFlyout(aFlyout);
+ myAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
+ myAspect->ArrowAspect()->SetLength(CONSTRAINT_TEXT_HEIGHT * 2);
+
+ SetMeasuredGeometry(aPnt1, aPnt2, myPlane->impl<gp_Ax3>());
+ AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode);
+}
+
+bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) const
+{
+ DataPtr aData = myConstraint->data();
+ if (myConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) {
+ std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
+ (aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
+ if (!anAttr)
+ return false;
+
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object());
+ if (!aFeature || aFeature->getKind() != SketchPlugin_Line::ID())
+ return false;
+
+ DataPtr aLineData = aFeature->data();
+ std::shared_ptr<GeomDataAPI_Point2D> aStartPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aLineData->attribute(SketchPlugin_Line::START_ID()));
+ std::shared_ptr<GeomDataAPI_Point2D> aEndPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aLineData->attribute(SketchPlugin_Line::END_ID()));
+ thePnt1 = myPlane->to3D(aStartPoint->x(), aStartPoint->y())->impl<gp_Pnt>();
+ thePnt2 = myPlane->to3D(aEndPoint->x(), aEndPoint->y())->impl<gp_Pnt>();
+ return true;
+
+ } else if (myConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint_A = SketcherPrs_Tools::getFeaturePoint(
+ aData, SketchPlugin_Constraint::ENTITY_A());
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint_B = SketcherPrs_Tools::getFeaturePoint(
+ aData, SketchPlugin_Constraint::ENTITY_B());
+
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt_A;
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt_B;
+ if (aPoint_A && aPoint_B) {
+ aPnt_A = aPoint_A->pnt();
+ aPnt_B = aPoint_B->pnt();
+ } else if (!aPoint_A && aPoint_B) {
+ std::shared_ptr<SketchPlugin_Line> aLine = SketcherPrs_Tools::getFeatureLine(
+ aData, SketchPlugin_Constraint::ENTITY_A());
+ if (aLine) {
+ aPnt_B = aPoint_B->pnt();
+ aPnt_A = SketcherPrs_Tools::getProjectionPoint(aLine, aPnt_B);
+ }
+ } else if (aPoint_A && !aPoint_B) {
+ std::shared_ptr<SketchPlugin_Line> aLine = SketcherPrs_Tools::getFeatureLine(
+ aData, SketchPlugin_Constraint::ENTITY_B());
+ if (aLine) {
+ aPnt_A = aPoint_A->pnt();
+ aPnt_B = SketcherPrs_Tools::getProjectionPoint(aLine, aPnt_A);
+ }
+ }
+ if (!aPnt_A || !aPnt_B)
+ return false;
+
+ std::shared_ptr<GeomAPI_Pnt> aPoint1 = myPlane->to3D(aPnt_A->x(), aPnt_A->y());
+ std::shared_ptr<GeomAPI_Pnt> aPoint2 = myPlane->to3D(aPnt_B->x(), aPnt_B->y());
+ thePnt1 = aPoint1->impl<gp_Pnt>();
+ thePnt2 = aPoint2->impl<gp_Pnt>();
+ return true;
+ }
+ return false;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_LengthDimension.h
+// Created: 27 March 2015
+// Author: Vitaly SMETANNIKOV
+
+
+#ifndef SketcherPrs_LinearDimension_H
+#define SketcherPrs_LinearDimension_H
+
+#include <GeomAPI_Ax3.h>
+#include <AIS_LengthDimension.hxx>
+#include <Standard_DefineHandle.hxx>
+
+
+class SketchPlugin_Constraint;
+
+DEFINE_STANDARD_HANDLE(SketcherPrs_LengthDimension, AIS_LengthDimension)
+
+/**
+* \ingroup GUI
+* A class for representation of linear dimension constraint.
+* It supports SketchPlugin_ConstraintLength and SketchPlugin_ConstraintDistance features.
+*/
+class SketcherPrs_LengthDimension : public AIS_LengthDimension
+{
+public:
+ /// Constructor
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ Standard_EXPORT SketcherPrs_LengthDimension(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
+ std::string constraintType() const;
+
+ DEFINE_STANDARD_RTTI(SketcherPrs_LengthDimension)
+protected:
+ /// Redefinition of virtual function
+ Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
+
+private:
+ bool getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2) const;
+
+ /// Constraint feature
+ SketchPlugin_Constraint* myConstraint;
+
+ /// Plane of the current sketcher
+ std::shared_ptr<GeomAPI_Ax3> myPlane;
+
+ Handle(Prs3d_DimensionAspect) myAspect;
+};
+
+#endif
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Radius.cpp
+// Created: 26 March 2015
+// Author: Vitaly SMETANNIKOV
+
+#include "SketcherPrs_Radius.h"
+
+#include <SketchPlugin_ConstraintRadius.h>
+#include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Arc.h>
+
+#include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Pnt2D.h>
+#include <GeomAPI_Circ.h>
+#include <GeomAPI_XYZ.h>
+#include <ModelAPI_AttributeDouble.h>
+
+const int CONSTRAINT_TEXT_HEIGHT = 20; /// the text height of the constraint
+const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection tolerance
+
+static gp_Circ MyDefCirc(gp_Ax2(gp_Pnt(0,0,0), gp_Dir(0,0,1)), 1);
+
+IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Radius, AIS_RadiusDimension);
+IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Radius, AIS_RadiusDimension);
+
+SketcherPrs_Radius::SketcherPrs_Radius(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+: AIS_RadiusDimension(MyDefCirc), myConstraint(theConstraint), myPlane(thePlane)
+{
+ myAspect = new Prs3d_DimensionAspect();
+ myAspect->MakeArrows3d(false);
+ myAspect->MakeText3d(false);
+ myAspect->MakeTextShaded(false);
+ myAspect->MakeUnitsDisplayed(false);
+
+ SetDimensionAspect(myAspect);
+ SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE);
+}
+
+
+void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
+{
+ DataPtr aData = myConstraint->data();
+
+ // Flyout point
+ std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+ if (!aFlyoutAttr->isInitialized())
+ return; // can not create a good presentation
+
+ std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = myPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
+
+ // Get circle
+ std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
+ (aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
+ if (!anAttr) return;
+
+ std::shared_ptr<ModelAPI_Feature> aCyrcFeature = ModelAPI_Feature::feature(anAttr->object());
+ double aRadius = 1;
+ std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
+ if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle
+ aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
+ AttributeDoublePtr aCircRadius =
+ std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+ aCyrcFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID()));
+ aRadius = aCircRadius->value();
+ } else { // arc
+ aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()));
+ std::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID()));
+ aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
+ }
+ std::shared_ptr<GeomAPI_Pnt> aCenter = myPlane->to3D(aCenterAttr->x(), aCenterAttr->y());
+ std::shared_ptr<GeomAPI_Dir> aNormal = myPlane->norm();
+
+ GeomAPI_Circ aCircle(aCenter, aNormal, aRadius);
+ //gp_Circ aCircle(gp_Ax2(aCenter->impl<gp_Pnt>(), aNormal->impl<gp_Dir>()), aRadius);
+
+ std::shared_ptr<GeomAPI_Pnt> anAnchor = aCircle.project(aFlyoutPnt);
+ std::shared_ptr<GeomAPI_XYZ> anAnchorXYZ = anAnchor->xyz();
+ anAnchorXYZ = anAnchorXYZ->decreased(aCenter->xyz());
+ std::shared_ptr<GeomAPI_Dir> aDeltaDir(new GeomAPI_Dir(anAnchorXYZ));
+ const double aDelta = 1e-3;
+ anAnchor->setX(anAnchor->x() + aDelta * aDeltaDir->x());
+ anAnchor->setY(anAnchor->y() + aDelta * aDeltaDir->y());
+ anAnchor->setZ(anAnchor->z() + aDelta * aDeltaDir->z());
+
+ SetMeasuredGeometry(aCircle.impl<gp_Circ>(), anAnchor->impl<gp_Pnt>());
+ SetCustomValue(aRadius);
+
+ myAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
+ myAspect->ArrowAspect()->SetLength(CONSTRAINT_TEXT_HEIGHT * 2.);
+ AIS_RadiusDimension::Compute(thePresentationManager, thePresentation, theMode);
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Radius.h
+// Created: 26 March 2015
+// Author: Vitaly SMETANNIKOV
+
+
+#ifndef SketcherPrs_Radius_H
+#define SketcherPrs_Radius_H
+
+#include <GeomAPI_Ax3.h>
+
+#include <AIS_RadiusDimension.hxx>
+#include <Standard_DefineHandle.hxx>
+
+class SketchPlugin_Constraint;
+
+DEFINE_STANDARD_HANDLE(SketcherPrs_Radius, AIS_RadiusDimension)
+
+/**
+* \ingroup GUI
+* A class for representation of radius constraint
+*/
+class SketcherPrs_Radius : public AIS_RadiusDimension
+{
+public:
+ /// Constructor
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ Standard_EXPORT SketcherPrs_Radius(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
+ DEFINE_STANDARD_RTTI(SketcherPrs_Radius)
+protected:
+ /// Redefinition of virtual function
+ Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
+
+private:
+ /// Constraint feature
+ SketchPlugin_Constraint* myConstraint;
+
+ /// Plane of the current sketcher
+ std::shared_ptr<GeomAPI_Ax3> myPlane;
+
+ Handle(Prs3d_DimensionAspect) myAspect;
+};
+
+#endif
\ No newline at end of file
#include <SketchPlugin_Constraint.h>
#include <SketchPlugin_Point.h>
#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Line.h>
+
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Lin2d.h>
namespace SketcherPrs_Tools {
return std::shared_ptr<GeomAPI_Pnt2d>();
}
+//*************************************************************************************
+std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
+ const std::string& theAttribute)
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
+
+ if (!theData)
+ return aPointAttr;
+
+ FeaturePtr aFeature;
+ std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
+ if (anAttr)
+ aFeature = ModelAPI_Feature::feature(anAttr->object());
+
+ if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()));
+
+ else if (aFeature && aFeature->getKind() == SketchPlugin_Circle::ID())
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
+
+ else if (anAttr->attr()) {
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+ }
+ return aPointAttr;
+}
+
+//*************************************************************************************
+std::shared_ptr<SketchPlugin_Line> getFeatureLine(DataPtr theData,
+ const std::string& theAttribute)
+{
+ std::shared_ptr<SketchPlugin_Line> aLine;
+ if (!theData)
+ return aLine;
+
+ std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
+ if (anAttr) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object());
+ if (aFeature && aFeature->getKind() == SketchPlugin_Line::ID()) {
+ aLine = std::dynamic_pointer_cast<SketchPlugin_Line>(aFeature);
+ }
+ }
+ return aLine;
+}
+
+//*************************************************************************************
+std::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(
+ const std::shared_ptr<SketchPlugin_Line>& theLine,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+ std::shared_ptr<ModelAPI_Data> aData = theLine->data();
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aData->attribute(SketchPlugin_Line::START_ID()));
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aData->attribute(SketchPlugin_Line::END_ID()));
+
+ GeomAPI_Lin2d aLin2d(aPoint1->x(), aPoint1->y(), aPoint2->x(), aPoint2->y());
+ return aLin2d.project(thePoint);
+}
};
\ No newline at end of file
#include <string>
class SketchPlugin_Constraint;
+class SketchPlugin_Line;
+class GeomDataAPI_Point2D;
namespace SketcherPrs_Tools {
- ObjectPtr getResult(SketchPlugin_Constraint* theFeature,
+ SKETCHERPRS_EXPORT ObjectPtr getResult(SketchPlugin_Constraint* theFeature,
const std::string& theAttrName);
- std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject);
+ SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Shape> getShape(ObjectPtr theObject);
- std::shared_ptr<GeomAPI_Pnt2d> getPoint(SketchPlugin_Constraint* theFeature,
+ SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getPoint(SketchPlugin_Constraint* theFeature,
const std::string& theAttrName);
+ SKETCHERPRS_EXPORT std::shared_ptr<GeomAPI_Pnt2d> getProjectionPoint(
+ const std::shared_ptr<SketchPlugin_Line>& theLine,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
+ SKETCHERPRS_EXPORT std::shared_ptr<SketchPlugin_Line> getFeatureLine(DataPtr theData,
+ const std::string& theAttribute);
+
+ /// Obtain the point object from specified constraint parameter
+ SKETCHERPRS_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
+ const std::string& theAttribute);
+
};
#endif
\ No newline at end of file