gp_Lin2d aPrjLine1 = ProjLib::Project(aPlane, *MY_LIN);
gp_Lin2d aPrjLine2 = ProjLib::Project(aPlane, theLine->impl<gp_Lin>());
- IntAna2d_AnaIntersection anInter(aPrjLine1, aPrjLine1);
+ IntAna2d_AnaIntersection anInter(aPrjLine1, aPrjLine2);
if (!anInter.IsDone() || anInter.IsEmpty())
return std::shared_ptr<GeomAPI_Pnt>();
- const gp_Pnt2d& anIntPnt2d = anInter.Point(0).Value();
+ const gp_Pnt2d& anIntPnt2d = anInter.Point(1).Value();
gp_Pnt aResult = ElSLib::Value(anIntPnt2d.X(), anIntPnt2d.Y(), aPlane);
return std::shared_ptr<GeomAPI_Pnt>(
SketchPlugin_ConstraintAngle::SketchPlugin_ConstraintAngle()
{
+ myFlyoutUpdate = false;
}
void SketchPlugin_ConstraintAngle::initAttributes()
data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
+ data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId());
}
void SketchPlugin_ConstraintAngle::execute()
if (!anAIS) {
anAIS = SketcherPrs_Factory::angleConstraint(this, sketch()->coordinatePlane());
}
+
+ // Set color from preferences
+ std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color",
+ SKETCH_DIMENSION_COLOR);
+ anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
double anAngle = calculateAngle();
aValueAttr->setValue(anAngle);
}
+ } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) {
+ // Recalculate flyout point in local coordinates
+ std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
}
}
anAngle = aDirA->angle(aDirB) * 180.0 / PI;
return anAngle;
}
+
+void SketchPlugin_ConstraintAngle::move(double theDeltaX, double theDeltaY)
+{
+ std::shared_ptr<ModelAPI_Data> aData = data();
+ if (!aData->isValid())
+ return;
+
+ myFlyoutUpdate = true;
+ std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = std::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+ aFlyoutAttr->setValue(aFlyoutAttr->x() + theDeltaX, aFlyoutAttr->y() + theDeltaY);
+ myFlyoutUpdate = false;
+}
/// Returns the AIS preview
SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+ /// Moves the feature
+ /// \param theDeltaX the delta for X coordinate is moved
+ /// \param theDeltaY the delta for Y coordinate is moved
+ SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+
/// Calculate current value of the angle
double calculateAngle();
/// \brief Use plugin manager for features creation
SketchPlugin_ConstraintAngle();
+
+private:
+ bool myFlyoutUpdate; ///< to avoid cyclic dependencies on automatic updates of flyout point
};
#endif
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
</shape_selector>
+ <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
<doublevalue_editor label="Value" tooltip="Angle" id="ConstraintValue" default="computed" />
<validator id="PartSet_AngleSelection"/>
</feature>
SketcherPrs_LengthDimension.h
SketcherPrs_Mirror.h
SketcherPrs_Transformation.h
+ SketcherPrs_Angle.h
)
SET(PROJECT_SOURCES
SketcherPrs_LengthDimension.cpp
SketcherPrs_Mirror.cpp
SketcherPrs_Transformation.cpp
+ SketcherPrs_Angle.cpp
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Angle.cpp
+// Created: 20 August 2015
+// Author: Vitaly SMETANNIKOV
+
+#include "SketcherPrs_Angle.h"
+#include "SketcherPrs_Tools.h"
+
+#include <SketchPlugin_ConstraintAngle.h>
+#include <SketchPlugin_Constraint.h>
+
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+#include <GeomDataAPI_Point2D.h>
+
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeDouble.h>
+
+#include <TopExp.hxx>
+#include <BRep_Tool.hxx>
+
+#define PI 3.1415926535897932
+
+IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension);
+IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Angle, AIS_AngleDimension);
+
+
+
+
+
+SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+: AIS_AngleDimension(gp_Pnt(0,0,0), gp_Pnt(1,0,0), gp_Pnt(0,1,0)), myConstraint(theConstraint), myPlane(thePlane)
+{
+ myAspect = new Prs3d_DimensionAspect();
+ myAspect->MakeArrows3d(false);
+ myAspect->MakeText3d(false);
+ myAspect->MakeTextShaded(false);
+ myAspect->MakeUnitsDisplayed(false);
+ myAspect->TextAspect()->SetHeight(SketcherPrs_Tools::getDefaultTextHeight());
+ myAspect->ArrowAspect()->SetLength(SketcherPrs_Tools::getArrowSize());
+
+ SetDimensionAspect(myAspect);
+ SetSelToleranceForText2d(SketcherPrs_Tools::getDefaultTextHeight());
+}
+
+void SketcherPrs_Angle::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());
+
+ AttributeRefAttrPtr anAttr1 = aData->refattr(SketchPlugin_Constraint::ENTITY_A());
+ if (!anAttr1->isInitialized())
+ return;
+
+ AttributeRefAttrPtr anAttr2 = aData->refattr(SketchPlugin_Constraint::ENTITY_B());
+ if (!anAttr2->isInitialized())
+ return;
+
+ // Get angle edges
+ ObjectPtr aObj1 = anAttr1->object();
+ ObjectPtr aObj2 = anAttr2->object();
+
+ std::shared_ptr<GeomAPI_Shape> aShape1 = SketcherPrs_Tools::getShape(aObj1);
+ std::shared_ptr<GeomAPI_Shape> aShape2 = SketcherPrs_Tools::getShape(aObj2);
+
+ if (!aShape1 && !aShape2)
+ return;
+
+ TopoDS_Shape aTEdge1 = aShape1->impl<TopoDS_Shape>();
+ TopoDS_Shape aTEdge2 = aShape2->impl<TopoDS_Shape>();
+
+ TopoDS_Edge aEdge1 = TopoDS::Edge(aTEdge1);
+ TopoDS_Edge aEdge2 = TopoDS::Edge(aTEdge2);
+ SetMeasuredGeometry(aEdge1, aEdge2);
+
+ // Compute intersection point
+ TopoDS_Vertex aV1, aV2;
+ TopExp::Vertices(aEdge1, aV1, aV2);
+ gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
+ gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
+ std::shared_ptr<GeomAPI_Lin> aL1(new GeomAPI_Lin(aPnt1.X(), aPnt1.Y(), aPnt1.Z(),
+ aPnt2.X(), aPnt2.Y(), aPnt2.Z()));
+ TopExp::Vertices(aEdge2, aV1, aV2);
+ aPnt1 = BRep_Tool::Pnt(aV1);
+ aPnt2 = BRep_Tool::Pnt(aV2);
+ std::shared_ptr<GeomAPI_Lin> aL2(new GeomAPI_Lin(aPnt1.X(), aPnt1.Y(), aPnt1.Z(),
+ aPnt2.X(), aPnt2.Y(), aPnt2.Z()));
+
+ std::shared_ptr<GeomAPI_Pnt> aInter = aL1->intersect(aL2);
+ gp_Pnt aCenter = aInter->impl<gp_Pnt>();
+
+ gp_Pnt aFLyPnt(aFlyoutPnt->x(), aFlyoutPnt->y(), aFlyoutPnt->z());
+ double aDist = aCenter.Distance(aFLyPnt);
+ SetFlyout(aDist);
+
+ // Angle value is in degrees
+ AttributeDoublePtr aVal = aData->real(SketchPlugin_Constraint::VALUE());
+ SetCustomValue(aVal->value() * PI / 180.0);
+
+ AIS_AngleDimension::Compute(thePresentationManager, thePresentation, theMode);
+}
+
+void SketcherPrs_Angle::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+ const Standard_Integer theMode)
+{
+ Standard_Integer aMode;
+ switch (theMode) {
+ case 0: // we should use selection of all objects
+ aMode = 0;
+ break;
+ case SketcherPrs_Tools::Sel_Dimension_All:
+ aMode = 0;
+ break;
+ case SketcherPrs_Tools::Sel_Dimension_Line:
+ aMode = 1;
+ break;
+ case SketcherPrs_Tools::Sel_Dimension_Text:
+ aMode = 2;
+ break;
+ default: {
+ // there are own selection modes, so the others should be ignored
+ // otherwise, the text selection appears in the viewer
+ return;
+ }
+ }
+ AIS_AngleDimension::ComputeSelection(aSelection, aMode);
+}
// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
// File: SketcherPrs_Angle.h
-// Created: 26 March 2015
+// Created: 20 August 2015
// Author: Vitaly SMETANNIKOV
#ifndef SketcherPrs_Angle_H
#define SketcherPrs_Angle_H
+#include <GeomAPI_Ax3.h>
+#include <ModelAPI_Feature.h>
+#include <AIS_AngleDimension.hxx>
+#include <Standard_DefineHandle.hxx>
-#endif
\ No newline at end of file
+DEFINE_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension)
+
+/**
+* \ingroup GUI
+* A class for representation of angle constraint
+*/
+class SketcherPrs_Angle : public AIS_AngleDimension
+{
+public:
+ /// Constructor
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ Standard_EXPORT SketcherPrs_Angle(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
+ DEFINE_STANDARD_RTTI(SketcherPrs_Angle)
+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);
+
+ /// Redefinition of virtual function
+ Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+ const Standard_Integer aMode);
+
+private:
+ /// Constraint feature
+ ModelAPI_Feature* myConstraint;
+
+ /// Plane of the current sketcher
+ std::shared_ptr<GeomAPI_Ax3> myPlane;
+
+ Handle(Prs3d_DimensionAspect) myAspect;
+};
+
+
+#endif
#include "SketcherPrs_LengthDimension.h"
#include "SketcherPrs_Mirror.h"
#include "SketcherPrs_Transformation.h"
+#include "SketcherPrs_Angle.h"
#define CONSTRAINT_PRS_IMPL(NAME, CLASS) \
AISObjectPtr SketcherPrs_Factory::NAME(ModelAPI_Feature* theConstraint, \
CONSTRAINT_PRS_IMPL(radiusConstraint, SketcherPrs_Radius);
CONSTRAINT_PRS_IMPL(lengthDimensionConstraint, SketcherPrs_LengthDimension);
CONSTRAINT_PRS_IMPL(mirrorConstraint, SketcherPrs_Mirror);
+CONSTRAINT_PRS_IMPL(angleConstraint, SketcherPrs_Angle);
AISObjectPtr SketcherPrs_Factory::horisontalConstraint(ModelAPI_Feature* theConstraint,
aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
return aAISObj;
}
-
-AISObjectPtr SketcherPrs_Factory::angleConstraint(ModelAPI_Feature* theConstraint,
- const std::shared_ptr<GeomAPI_Ax3>& thePlane)
-{
- return AISObjectPtr(new GeomAPI_AISObject());
-}
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);
SetFlyout(SketcherPrs_Tools::getFlyoutDistance(myConstraint));
SetMeasuredGeometry(aPnt1, aPnt2, myPlane->impl<gp_Ax3>());
AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode);
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>
GeomAPI_Circ aCircle(aCenter, aNormal, aRadius);
std::shared_ptr<GeomAPI_Pnt> anAnchor = SketcherPrs_Tools::getAnchorPoint(myConstraint, myPlane);
- //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);