#include "SketcherPrs_Tools.h"
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_Events.h>
+
#include <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Dir.h>
#include <GeomDataAPI_Point.h>
SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane)
- : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
+ : AIS_InteractiveObject(), myConstraint(theConstraint), mySketcherPlane(thePlane)
{
}
const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer theMode)
{
- if (!IsReadyToDisplay(myConstraint, myPlane)) {
- Events_Error::throwException("An empty AIS presentation: SketcherPrs_Coincident");
- return;
+ bool aReadyToDisplay = IsReadyToDisplay(myConstraint, mySketcherPlane);
+ if (aReadyToDisplay) {
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint,
+ SketchPlugin_Constraint::ENTITY_A());
+ if (aPnt.get() == NULL)
+ aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+ std::shared_ptr<GeomAPI_Pnt> aPoint = mySketcherPlane->to3D(aPnt->x(), aPnt->y());
+ myPoint = aPoint->impl<gp_Pnt>();
}
// Get point of the presentation
- std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint,
- SketchPlugin_Constraint::ENTITY_A());
- if (aPnt.get() == NULL)
- aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_B());
- std::shared_ptr<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y());
- myPoint = aPoint->impl<gp_Pnt>();
-
static Handle(Graphic3d_AspectMarker3d) aPtA;
if (aPtA.IsNull()) {
aPtA = new Graphic3d_AspectMarker3d ();
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
aGroup->SetPrimitivesAspect(aPtA);
Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
- aPntArray->AddVertex (aPoint->x(), aPoint->y(), aPoint->z());
+ aPntArray->AddVertex (myPoint.X(), myPoint.Y(), myPoint.Z());
aGroup->AddPrimitiveArray (aPntArray);
// Make a black mid ring
aPtA->SetScale(5.);
aGroup->SetPrimitivesAspect(aPtA);
aGroup->AddPrimitiveArray (aPntArray);
+
+ if (!aReadyToDisplay)
+ SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
+ "An empty AIS presentation: SketcherPrs_Coincident");
}
private:
ModelAPI_Feature* myConstraint;
- std::shared_ptr<GeomAPI_Ax3> myPlane;
+ std::shared_ptr<GeomAPI_Ax3> mySketcherPlane;
gp_Pnt myPoint;
};
#include "SketcherPrs_LengthDimension.h"
#include "SketcherPrs_Tools.h"
-#include "SketcherPrs_Tools.h"
#include "SketcherPrs_DimensionStyleListener.h"
#include <SketchPlugin_Constraint.h>
#include <SketchPlugin_Circle.h>
#include <Events_Error.h>
-#include <Events_Loop.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Lin2d.h>
#include <ModelAPI_Data.h>
-#include <ModelAPI_Events.h>
#include <ModelAPI_AttributeDouble.h>
#include <AIS_DisplaySpecialSymbol.hxx>
myConstraint(theConstraint),
mySketcherPlane(thePlane)
{
- Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
-
- anAspect->MakeArrows3d(false);
- anAspect->MakeText3d(false);
- anAspect->MakeTextShaded(false);
- anAspect->MakeUnitsDisplayed(false);
- anAspect->TextAspect()->SetHeight(SketcherPrs_Tools::getDefaultTextHeight());
- anAspect->ArrowAspect()->SetLength(SketcherPrs_Tools::getArrowSize());
-
+ SetDimensionAspect(SketcherPrs_Tools::createDimensionAspect());
SetSelToleranceForText2d(SketcherPrs_Tools::getTextHeight());
- SetDimensionAspect(anAspect);
myStyleListener = new SketcherPrs_DimensionStyleListener();
}
}
void SketcherPrs_LengthDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
- const Handle(Prs3d_Presentation)& thePresentation,
- const Standard_Integer theMode)
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
{
- bool aReadyToDisplay = SketcherPrs_LengthDimension::IsReadyToDisplay(myConstraint, mySketcherPlane);
+ bool aReadyToDisplay = IsReadyToDisplay(myConstraint, mySketcherPlane);
if (aReadyToDisplay) {
myDistance = SketcherPrs_Tools::getFlyoutDistance(myConstraint);
getPoints(myConstraint, mySketcherPlane, myFirstPoint, mySecondPoint);
SetMeasuredGeometry(myFirstPoint, mySecondPoint, myPlane);
// Update variable aspect parameters (depending on viewer scale)
- updateArrows();
+ double aTextSize = 0.0;
+ GetValueString(aTextSize);
+ SketcherPrs_Tools::updateArrows(DimensionAspect(), GetValue(), aTextSize);
+ // Update text visualization: parameter value or parameter text
myStyleListener->updateDimensions(this, myHasParameters, myValue);
AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode);
- if (!aReadyToDisplay) {
- Events_Error::throwException("An empty AIS presentation: SketcherPrs_LengthDimension");
- static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
- std::shared_ptr<ModelAPI_Object> aConstraintPtr(myConstraint);
- ModelAPI_EventCreator::get()->sendUpdated(aConstraintPtr, anEvent);
- }
+ if (!aReadyToDisplay)
+ SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
+ "An empty AIS presentation: SketcherPrs_LengthDimension");
+
}
bool SketcherPrs_LengthDimension::getPoints(ModelAPI_Feature* theConstraint,
SetSelToleranceForText2d(SketcherPrs_Tools::getTextHeight());
AIS_LengthDimension::ComputeSelection(aSelection, aMode);
}
-
-void SketcherPrs_LengthDimension::updateArrows()
-{
- Handle(Prs3d_DimensionAspect) anAspect = DimensionAspect();
-
- double anArrowLength = anAspect->ArrowAspect()->Length();
- // This is not realy correct way to get viewer scale.
- double aViewerScale = (double) SketcherPrs_Tools::getDefaultArrowSize() / anArrowLength;
- double aDimensionValue = GetValue();
- double aTextSize = 0.0;
- GetValueString(aTextSize);
-
- if(aTextSize > ((aDimensionValue - 3 * SketcherPrs_Tools::getArrowSize()) * aViewerScale)) {
- anAspect->SetTextHorizontalPosition(Prs3d_DTHP_Left);
- anAspect->SetArrowOrientation(Prs3d_DAO_External);
- anAspect->SetExtensionSize(aTextSize / aViewerScale - SketcherPrs_Tools::getArrowSize() / 2.0);
- } else {
- anAspect->SetTextHorizontalPosition(Prs3d_DTHP_Center);
- anAspect->SetArrowOrientation(Prs3d_DAO_Internal);
- }
- anAspect->SetArrowTailSize(anAspect->ArrowAspect()->Length());
- // The value of vertical aligment is sometimes changed
- anAspect->TextAspect()->SetVerticalJustification(Graphic3d_VTA_CENTER);
-}
const std::shared_ptr<GeomAPI_Ax3>& thePlane,
gp_Pnt& thePnt1, gp_Pnt& thePnt2);
- /// Update variable aspect parameters (depending on viewer scale)
- void updateArrows();
-
/// Constraint feature
ModelAPI_Feature* myConstraint;
/// Listener to update dimension visualization style
SketcherPrs_DimensionStyleListener* myStyleListener;
+ /// container of values obtained from the constraint, which are necessary to fill the presentation
double myDistance; ///< the flyout distance
gp_Pnt myFirstPoint; ///< the dimension first point for measured geometry
gp_Pnt mySecondPoint; ///< the dimension first point for measured geometry
SketcherPrs_Radius::SketcherPrs_Radius(ModelAPI_Feature* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane)
-: AIS_RadiusDimension(MyDefCirc), myConstraint(theConstraint), myPlane(thePlane)
+: AIS_RadiusDimension(MyDefCirc), myConstraint(theConstraint), mySketcherPlane(thePlane)
{
- // Set default values of the presentation
- 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);
+ SetDimensionAspect(SketcherPrs_Tools::createDimensionAspect());
SetSelToleranceForText2d(SketcherPrs_Tools::getDefaultTextHeight());
myStyleListener = new SketcherPrs_DimensionStyleListener();
const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer theMode)
{
- if (!IsReadyToDisplay(myConstraint, myPlane)) {
- Events_Error::throwException("An empty AIS presentation: SketcherPrs_Radius");
- return;
- }
+ bool aReadyToDisplay = IsReadyToDisplay(myConstraint, mySketcherPlane);
+ if (aReadyToDisplay) {
+ //myDistance = SketcherPrs_Tools::getFlyoutDistance(myConstraint);
- DataPtr aData = myConstraint->data();
+ 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()));
-
- // Get circle
- std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
- (aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
-
- 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 =
+ // Flyout point
+ std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>
- (aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID()));
- aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
+ (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+
+ // Get circle
+ std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
+ (aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
+
+ std::shared_ptr<ModelAPI_Feature> aCyrcFeature = ModelAPI_Feature::feature(anAttr->object());
+ myRadius = 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()));
+ myRadius = 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()));
+ myRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
+ }
+ std::shared_ptr<GeomAPI_Pnt> aCenter = mySketcherPlane->to3D(aCenterAttr->x(), aCenterAttr->y());
+ std::shared_ptr<GeomAPI_Dir> aNormal = mySketcherPlane->normal();
+
+ GeomAPI_Circ aCircle(aCenter, aNormal, myRadius);
+ std::shared_ptr<GeomAPI_Pnt> anAnchor = SketcherPrs_Tools::getAnchorPoint(myConstraint, mySketcherPlane);
+
+ myCircle = aCircle.impl<gp_Circ>();
+ myAncorPnt = anAnchor->impl<gp_Pnt>();
+
+ AttributeDoublePtr anAttributeValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE());
+ myHasParameters = anAttributeValue->usedParameters().size() > 0;
+ myValue = anAttributeValue->text();
}
- std::shared_ptr<GeomAPI_Pnt> aCenter = myPlane->to3D(aCenterAttr->x(), aCenterAttr->y());
- std::shared_ptr<GeomAPI_Dir> aNormal = myPlane->normal();
-
- GeomAPI_Circ aCircle(aCenter, aNormal, aRadius);
-
- std::shared_ptr<GeomAPI_Pnt> anAnchor = SketcherPrs_Tools::getAnchorPoint(myConstraint, myPlane);
- gp_Circ aCirc = aCircle.impl<gp_Circ>();
- gp_Pnt anAncorPnt = anAnchor->impl<gp_Pnt>();
-
- SetMeasuredGeometry(aCirc, anAncorPnt);
- SetCustomValue(aRadius);
+ SetMeasuredGeometry(myCircle, myAncorPnt);
+ SetCustomValue(myRadius);
// Update variable aspect parameters (depending on viewer scale)
- double anArrowLength = myAspect->ArrowAspect()->Length();
- // This is not realy correct way to get viewer scale.
- double aViewerScale = (double) SketcherPrs_Tools::getDefaultArrowSize() / anArrowLength;
- double aDimensionValue = GetValue();
double aTextSize = 0.0;
GetValueString(aTextSize);
+ SketcherPrs_Tools::updateArrows(DimensionAspect(), GetValue(), aTextSize);
- if(aTextSize > ((aDimensionValue - 2 * SketcherPrs_Tools::getArrowSize()) * aViewerScale)) {
- myAspect->SetTextHorizontalPosition(Prs3d_DTHP_Left);
- myAspect->SetArrowOrientation(Prs3d_DAO_External);
- myAspect->SetExtensionSize(aTextSize / aViewerScale - SketcherPrs_Tools::getArrowSize() / 2.0);
- } else {
- myAspect->SetTextHorizontalPosition(Prs3d_DTHP_Center);
- myAspect->SetArrowOrientation(Prs3d_DAO_Internal);
- }
- myAspect->SetArrowTailSize(myAspect->ArrowAspect()->Length());
-
- // The value of vertical aligment is sometimes changed
- myAspect->TextAspect()->SetVerticalJustification(Graphic3d_VTA_CENTER);
-
- AttributeDoublePtr aValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE());
- SketcherPrs_Tools::setDisplaySpecialSymbol(this, aValue->usedParameters().size() > 0);
-
- myStyleListener->updateDimensions(this, aValue);
-
+ myStyleListener->updateDimensions(this, myHasParameters, myValue);
+
AIS_RadiusDimension::Compute(thePresentationManager, thePresentation, theMode);
+
+ if (!aReadyToDisplay)
+ SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
+ "An empty AIS presentation: SketcherPrs_Radius");
}
void SketcherPrs_Radius::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
ModelAPI_Feature* myConstraint;
/// Plane of the current sketcher
- std::shared_ptr<GeomAPI_Ax3> myPlane;
-
- Handle(Prs3d_DimensionAspect) myAspect;
+ std::shared_ptr<GeomAPI_Ax3> mySketcherPlane;
/// Listener to update dimension visualization style
SketcherPrs_DimensionStyleListener* myStyleListener;
+
+ /// container of values obtained from the constraint, which are necessary to fill the presentation
+ double myRadius; ///< the radius custom value
+ gp_Circ myCircle; ///< the radius circle
+ gp_Pnt myAncorPnt; ///< an ancor for the radius value visualization
+
+ bool myHasParameters; ///< true if the atrribute value has used parameters
+ std::string myValue; ///< dimension value
};
#endif
\ No newline at end of file
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Events.h>
+
+#include <Events_Error.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Lin2d.h>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
+#include <Prs3d_DimensionAspect.hxx>
+
#include <BRep_Tool.hxx>
#include <Precision.hxx>
Events_Loop::loop()->flush(anId);
}
+Handle(Prs3d_DimensionAspect) createDimensionAspect()
+{
+ Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
+ anAspect->MakeArrows3d(false);
+ anAspect->MakeText3d(false);
+ anAspect->MakeTextShaded(false);
+ anAspect->MakeUnitsDisplayed(false);
+ anAspect->TextAspect()->SetHeight(SketcherPrs_Tools::getDefaultTextHeight());
+ anAspect->ArrowAspect()->SetLength(SketcherPrs_Tools::getArrowSize());
+
+ return anAspect;
+}
+
+void updateArrows(Handle(Prs3d_DimensionAspect) theDimAspect, double theDimValue, double theTextSize)
+{
+ double anArrowLength = theDimAspect->ArrowAspect()->Length();
+ // This is not realy correct way to get viewer scale.
+ double aViewerScale = (double) SketcherPrs_Tools::getDefaultArrowSize() / anArrowLength;
+
+ if(theTextSize > ((theDimValue - 3 * SketcherPrs_Tools::getArrowSize()) * aViewerScale)) {
+ theDimAspect->SetTextHorizontalPosition(Prs3d_DTHP_Left);
+ theDimAspect->SetArrowOrientation(Prs3d_DAO_External);
+ theDimAspect->SetExtensionSize(theTextSize / aViewerScale - SketcherPrs_Tools::getArrowSize() / 2.0);
+ } else {
+ theDimAspect->SetTextHorizontalPosition(Prs3d_DTHP_Center);
+ theDimAspect->SetArrowOrientation(Prs3d_DAO_Internal);
+ }
+ theDimAspect->SetArrowTailSize(theDimAspect->ArrowAspect()->Length());
+ // The value of vertical aligment is sometimes changed
+ theDimAspect->TextAspect()->SetVerticalJustification(Graphic3d_VTA_CENTER);
+}
+
+void sendEmptyPresentationError(ModelAPI_Feature* theFeature, const std::string theError)
+{
+ Events_Error::throwException("An empty AIS presentation: SketcherPrs_LengthDimension");
+ static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION);
+ std::shared_ptr<ModelAPI_Object> aConstraintPtr(theFeature);
+ ModelAPI_EventCreator::get()->sendUpdated(aConstraintPtr, anEvent);
+}
};
class GeomDataAPI_Point2D;
class AIS_Dimension;
+class Handle_Prs3d_DimensionAspect;
//#define MyTextHeight 20
/// \param theState a new state
SKETCHERPRS_EXPORT void sendExpressionShownEvent(const bool& theState);
+ /// Creates an aspect to be shown in length/radius dimension presentations
+ /// \return an instance of aspect
+ SKETCHERPRS_EXPORT Handle_Prs3d_DimensionAspect createDimensionAspect();
+
+ /// Update variable aspect parameters (depending on viewer scale)
+ /// \param theDimAspect an aspect to be changed
+ /// \param theDimValue an arrow value
+ /// \param theTextSize an arrow value
+ SKETCHERPRS_EXPORT void updateArrows(Handle_Prs3d_DimensionAspect theDimAspect,
+ double theDimValue, double theTextSize);
+
+ /// Throws an exception(in debug mode) and sends a signal about necessity to hide the object
+ /// \param theFeature a feature where AIS presentation is empty
+ /// \param theError a debug error information
+ SKETCHERPRS_EXPORT void sendEmptyPresentationError(ModelAPI_Feature* theFeature,
+ const std::string theError);
};
#endif