if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- anAIS = SketcherPrs_Factory::angleConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS = SketcherPrs_Factory::angleConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- anAIS = SketcherPrs_Factory::coincidentConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS = SketcherPrs_Factory::coincidentConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- // TODO
- //anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS;
+ // TODO
+ //AISObjectPtr anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane(),
+ // thePrevious);
return anAIS;
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- anAIS = SketcherPrs_Factory::equalConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS = SketcherPrs_Factory::equalConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
-
- if (!anAIS) {
- anAIS = SketcherPrs_Factory::horisontalConstraint(this, sketch()->coordinatePlane());
- /*
- ObjectPtr aObj = SketcherPrs_Tools::getResult(this, SketchPlugin_Constraint::ENTITY_A());
- if (SketcherPrs_Tools::getShape(aObj).get() != NULL) {
- anAIS = SketcherPrs_Factory::horisontalConstraint(this, sketch()->coordinatePlane());
- }*/
- }
- /*else {
- ObjectPtr aObj = SketcherPrs_Tools::getResult(this, SketchPlugin_Constraint::ENTITY_A());
- if (SketcherPrs_Tools::getShape(aObj).get() == NULL) {
- anAIS = AISObjectPtr();
- }
- }*/
+ AISObjectPtr anAIS = SketcherPrs_Factory::horisontalConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
-
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- // TODO
- //anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS;
+ // TODO
+ //AISObjectPtr anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane(),
+ // thePrevious);
return anAIS;
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- anAIS = SketcherPrs_Factory::mirrorConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS = SketcherPrs_Factory::mirrorConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- anAIS = SketcherPrs_Factory::parallelConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS = SketcherPrs_Factory::parallelConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- anAIS = SketcherPrs_Factory::perpendicularConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS = SketcherPrs_Factory::perpendicularConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- anAIS = SketcherPrs_Factory::radiusConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS = SketcherPrs_Factory::radiusConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
return thePrevious;
AISObjectPtr anAIS = thePrevious;
- if (anAIS.get() == NULL) {
- std::shared_ptr<ModelAPI_Data> aData = data();
- std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
- ObjectPtr aObj = anAttr->object();
- if (aObj.get() != NULL) {
- FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
- std::shared_ptr<SketchPlugin_Feature> aSkFea =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
- if (!aSkFea->isExternal())
- anAIS = SketcherPrs_Factory::rigidConstraint(this, sketch()->coordinatePlane());
- }
+
+ bool isValidRigid = false;
+ std::shared_ptr<ModelAPI_Data> aData = data();
+ AttributeRefAttrPtr anAttr = aData->refattr(SketchPlugin_Constraint::ENTITY_A());
+ ObjectPtr aObj = anAttr->object();
+ if (aObj.get() != NULL) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
+ std::shared_ptr<SketchPlugin_Feature> aSkFea =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+ if (!aSkFea->isExternal())
+ isValidRigid = true;
}
+ if (isValidRigid)
+ anAIS = SketcherPrs_Factory::rigidConstraint(this, sketch()->coordinatePlane(), thePrevious);
+ else
+ anAIS = AISObjectPtr();
+
return anAIS;
}
\ No newline at end of file
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- anAIS = SketcherPrs_Factory::tangentConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS = SketcherPrs_Factory::tangentConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- anAIS = SketcherPrs_Factory::verticalConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS = SketcherPrs_Factory::verticalConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- anAIS = SketcherPrs_Factory::rotateConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS = SketcherPrs_Factory::rotateConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS) {
- anAIS = SketcherPrs_Factory::translateConstraint(this, sketch()->coordinatePlane());
- }
+ AISObjectPtr anAIS = SketcherPrs_Factory::translateConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
SetSelToleranceForText2d(SketcherPrs_Tools::getDefaultTextHeight());
}
+bool SketcherPrs_Angle::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
+{
+ bool aReadyToDisplay = false;
+
+ DataPtr aData = theConstraint->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 aReadyToDisplay; // can not create a good presentation
+
+ AttributeRefAttrPtr anAttr1 = aData->refattr(SketchPlugin_Constraint::ENTITY_A());
+ if (!anAttr1->isInitialized())
+ return aReadyToDisplay;
+
+ AttributeRefAttrPtr anAttr2 = aData->refattr(SketchPlugin_Constraint::ENTITY_B());
+ if (!anAttr2->isInitialized())
+ return aReadyToDisplay;
+
+ // 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);
+
+ aReadyToDisplay = aShape1.get() && aShape2.get();
+ return aReadyToDisplay;
+}
+
void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer theMode)
{
DataPtr aData = myConstraint->data();
+ if (!IsReadyToDisplay(myConstraint, myPlane)) {
+ Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle");
+ return; // can not create a good presentation
+ }
+
// Flyout point
std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>
(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
- if (!aFlyoutAttr->isInitialized()) {
- Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle");
- 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()) {
- Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle");
- return;
- }
-
AttributeRefAttrPtr anAttr2 = aData->refattr(SketchPlugin_Constraint::ENTITY_B());
- if (!anAttr2->isInitialized()) {
- Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle");
- 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) {
- Events_Error::throwException("An empty AIS presentation: SketcherPrs_Angle");
- return;
- }
-
TopoDS_Shape aTEdge1 = aShape1->impl<TopoDS_Shape>();
TopoDS_Shape aTEdge2 = aShape2->impl<TopoDS_Shape>();
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
DEFINE_STANDARD_RTTI(SketcherPrs_Angle)
+
+ /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ /// \return boolean result value
+ static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
protected:
/// Redefinition of virtual function
Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
}
+bool SketcherPrs_Coincident::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
+{
+ bool aReadyToDisplay = false;
+
+ // Get point of the presentation
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theConstraint,
+ SketchPlugin_Constraint::ENTITY_A());
+ if (aPnt.get() == NULL)
+ aPnt = SketcherPrs_Tools::getPoint(theConstraint, SketchPlugin_Constraint::ENTITY_B());
+
+ aReadyToDisplay = aPnt.get() != NULL;
+ return aReadyToDisplay;
+}
void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
const Handle(Prs3d_Presentation)& thePresentation,
const Standard_Integer theMode)
{
+ if (!IsReadyToDisplay(myConstraint, myPlane)) {
+ Events_Error::throwException("An empty AIS presentation: SketcherPrs_Coincident");
+ return;
+ }
+
// 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());
- if (aPnt.get() == NULL) {
- Events_Error::throwException("An empty AIS presentation: SketcherPrs_Coincident");
- return;
- }
std::shared_ptr<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y());
myPoint = aPoint->impl<gp_Pnt>();
/// Defines color for the presentation
/// \param aColor a color name
Standard_EXPORT virtual void SetColor(const Quantity_NameOfColor aColor);
-
+
+ /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ /// \return boolean result value
+ static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
DEFINE_STANDARD_RTTI(SketcherPrs_Coincident)
protected:
/// Redefinition of virtual function
#include <SketchPlugin_Constraint.h>
+#include "Events_Error.h"
+
#include <Graphic3d_AspectLine3d.hxx>
#include <Prs3d_Root.hxx>
myPntArray->AddVertex(0., 0., 0.);
}
+bool SketcherPrs_Equal::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
+{
+ bool aReadyToDisplay = false;
+
+ ObjectPtr aObj1 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
+ ObjectPtr aObj2 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B());
+
+ aReadyToDisplay = SketcherPrs_Tools::getShape(aObj1).get() != NULL &&
+ SketcherPrs_Tools::getShape(aObj2).get() != NULL;
+
+ return aReadyToDisplay;
+}
+
bool SketcherPrs_Equal::updatePoints(double theStep) const
{
+ if (!IsReadyToDisplay(myConstraint, myPlane)) {
+ return false;
+ }
+
ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
- if (SketcherPrs_Tools::getShape(aObj1).get() == NULL)
- return false;
- if (SketcherPrs_Tools::getShape(aObj2).get() == NULL)
- return false;
// Set points of the presentation
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
Standard_EXPORT SketcherPrs_Equal(ModelAPI_Feature* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
DEFINE_STANDARD_RTTI(SketcherPrs_Equal)
+
+ /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ /// \return boolean result value
+ static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
protected:
virtual const char* iconName() const { return "equal.png"; }
// Macros for constraint presentation definition
#define CONSTRAINT_PRS_IMPL(NAME, CLASS) \
AISObjectPtr SketcherPrs_Factory::NAME(ModelAPI_Feature* theConstraint, \
- const std::shared_ptr<GeomAPI_Ax3>& thePlane) \
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane, \
+ AISObjectPtr thePrevious) \
{ \
- std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject()); \
- Handle(CLASS) aPrs = new CLASS(theConstraint, thePlane); \
- aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); \
- return aAISObj; \
+ std::shared_ptr<GeomAPI_AISObject> anAISObj; \
+ if (CLASS::IsReadyToDisplay(theConstraint, thePlane)) { \
+ if (thePrevious.get()) \
+ anAISObj = thePrevious; \
+ else { \
+ anAISObj = AISObjectPtr(new GeomAPI_AISObject()); \
+ Handle(CLASS) aPrs = new CLASS(theConstraint, thePlane); \
+ anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs)); \
+ } \
+ } \
+ return anAISObj; \
}
CONSTRAINT_PRS_IMPL(coincidentConstraint, SketcherPrs_Coincident);
// Non-standard constraints definition
AISObjectPtr SketcherPrs_Factory::horisontalConstraint(ModelAPI_Feature* theConstraint,
- const std::shared_ptr<GeomAPI_Ax3>& thePlane)
-{
- std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
- Handle(SketcherPrs_HVDirection) aPrs = new SketcherPrs_HVDirection(theConstraint, thePlane, true);
- aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
- return aAISObj;
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+ AISObjectPtr thePrevious)
+{
+ std::shared_ptr<GeomAPI_AISObject> anAISObj;
+ if (SketcherPrs_HVDirection::IsReadyToDisplay(theConstraint, thePlane)) {
+ if (thePrevious.get())
+ anAISObj = thePrevious;
+ else {
+ anAISObj = AISObjectPtr(new GeomAPI_AISObject());
+ Handle(SketcherPrs_HVDirection) aPrs = new SketcherPrs_HVDirection(theConstraint, thePlane, true);
+ anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
+ }
+ }
+ return anAISObj;
}
AISObjectPtr SketcherPrs_Factory::verticalConstraint(ModelAPI_Feature* theConstraint,
- const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+ AISObjectPtr thePrevious)
{
- std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
- Handle(SketcherPrs_HVDirection) aPrs = new SketcherPrs_HVDirection(theConstraint, thePlane, false);
- aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
- return aAISObj;
+ std::shared_ptr<GeomAPI_AISObject> anAISObj;
+ if (SketcherPrs_HVDirection::IsReadyToDisplay(theConstraint, thePlane)) {
+ if (thePrevious.get())
+ anAISObj = thePrevious;
+ else {
+ anAISObj = AISObjectPtr(new GeomAPI_AISObject());
+ Handle(SketcherPrs_HVDirection) aPrs = new SketcherPrs_HVDirection(theConstraint, thePlane, false);
+ anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
+ }
+ }
+ return anAISObj;
}
AISObjectPtr SketcherPrs_Factory::translateConstraint(ModelAPI_Feature* theConstraint,
- const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+ AISObjectPtr thePrevious)
{
- std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
- Handle(SketcherPrs_Transformation) aPrs = new SketcherPrs_Transformation(theConstraint, thePlane, true);
- aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
- return aAISObj;
+ std::shared_ptr<GeomAPI_AISObject> anAISObj;
+ if (SketcherPrs_Transformation::IsReadyToDisplay(theConstraint, thePlane)) {
+ if (thePrevious.get())
+ anAISObj = thePrevious;
+ else {
+ anAISObj = AISObjectPtr(new GeomAPI_AISObject());
+ Handle(SketcherPrs_Transformation) aPrs = new SketcherPrs_Transformation(theConstraint, thePlane, true);
+ anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
+ }
+ }
+ return anAISObj;
}
AISObjectPtr SketcherPrs_Factory::rotateConstraint(ModelAPI_Feature* theConstraint,
- const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+ AISObjectPtr thePrevious)
{
- std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
- Handle(SketcherPrs_Transformation) aPrs = new SketcherPrs_Transformation(theConstraint, thePlane, false);
- aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
- return aAISObj;
+ std::shared_ptr<GeomAPI_AISObject> anAISObj;
+ if (SketcherPrs_Transformation::IsReadyToDisplay(theConstraint, thePlane)) {
+ if (thePrevious.get())
+ anAISObj = thePrevious;
+ else {
+ anAISObj = AISObjectPtr(new GeomAPI_AISObject());
+ Handle(SketcherPrs_Transformation) aPrs = new SketcherPrs_Transformation(theConstraint, thePlane, false);
+ anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
+ }
+ }
+ return anAISObj;
}
#define GET_CONSTRAINT_PRS(NAME) \
static AISObjectPtr NAME(ModelAPI_Feature* theConstraint, \
- const std::shared_ptr<GeomAPI_Ax3>& thePlane);
-
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane, \
+ AISObjectPtr thePrevious);
/**
* Class which creates constraints presentations
#include <Graphic3d_AspectLine3d.hxx>
#include <Prs3d_Root.hxx>
+#include <Events_Error.h>
IMPLEMENT_STANDARD_HANDLE(SketcherPrs_HVDirection, SketcherPrs_SymbolPrs);
myPntArray->AddVertex(0., 0., 0.);
}
+bool SketcherPrs_HVDirection::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
+{
+ bool aReadyToDisplay = false;
+ ObjectPtr aObj = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
+
+ aReadyToDisplay = SketcherPrs_Tools::getShape(aObj).get() != NULL;
+ return aReadyToDisplay;
+}
+
bool SketcherPrs_HVDirection::updatePoints(double theStep) const
{
- ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
- if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
+ if (!SketcherPrs_HVDirection::IsReadyToDisplay(myConstraint, myPlane)) {
return false;
+ }
// Set point of the symbol
+ ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep);
myPntArray->SetVertice(1, aP1);
bool isHorisontal);
DEFINE_STANDARD_RTTI(SketcherPrs_HVDirection)
+
+ /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ /// \return boolean result value
+ static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
protected:
virtual const char* iconName() const { return myIsHorisontal? "horisontal.png" : "vertical.png"; }
SetDimensionAspect(myAspect);
}
+bool SketcherPrs_LengthDimension::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+{
+ bool aReadyToDisplay = false;
+
+ gp_Pnt aPnt1, aPnt2;
+ aReadyToDisplay = getPoints(theConstraint, thePlane, aPnt1, aPnt2);
+
+ return aReadyToDisplay;
+}
+
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)) {
+ if (!SketcherPrs_LengthDimension::IsReadyToDisplay(myConstraint, myPlane)) {
Events_Error::throwException("An empty AIS presentation: SketcherPrs_LengthDimension");
return;
}
+ gp_Pnt aPnt1, aPnt2;
+ getPoints(myConstraint, myPlane, aPnt1, aPnt2);
+
// compute flyout distance
SetFlyout(SketcherPrs_Tools::getFlyoutDistance(myConstraint));
SetMeasuredGeometry(aPnt1, aPnt2, myPlane->impl<gp_Ax3>());
AIS_LengthDimension::Compute(thePresentationManager, thePresentation, theMode);
}
-bool SketcherPrs_LengthDimension::getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2)
+bool SketcherPrs_LengthDimension::getPoints(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+ gp_Pnt& thePnt1, gp_Pnt& thePnt2)
{
- DataPtr aData = myConstraint->data();
- if (myConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) {
+ DataPtr aData = theConstraint->data();
+ if (theConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) {
// The constraint is length
std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
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>();
+ thePnt1 = thePlane->to3D(aStartPoint->x(), aStartPoint->y())->impl<gp_Pnt>();
+ thePnt2 = thePlane->to3D(aEndPoint->x(), aEndPoint->y())->impl<gp_Pnt>();
return true;
- } else if (myConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
+ } else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
// The constraint is distance
std::shared_ptr<GeomDataAPI_Point2D> aPoint_A = SketcherPrs_Tools::getFeaturePoint(
- aData, SketchPlugin_Constraint::ENTITY_A(), myPlane);
+ aData, SketchPlugin_Constraint::ENTITY_A(), thePlane);
std::shared_ptr<GeomDataAPI_Point2D> aPoint_B = SketcherPrs_Tools::getFeaturePoint(
- aData, SketchPlugin_Constraint::ENTITY_B(), myPlane);
+ aData, SketchPlugin_Constraint::ENTITY_B(), thePlane);
std::shared_ptr<GeomAPI_Pnt2d> aPnt_A;
std::shared_ptr<GeomAPI_Pnt2d> aPnt_B;
if (!aPnt_A || !aPnt_B) // Objects not found
return false;
- // Get points from these objects
- 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());
+ // Get points from these object
+ std::shared_ptr<GeomAPI_Pnt> aPoint1 = thePlane->to3D(aPnt_A->x(), aPnt_A->y());
+ std::shared_ptr<GeomAPI_Pnt> aPoint2 = thePlane->to3D(aPnt_B->x(), aPnt_B->y());
thePnt1 = aPoint1->impl<gp_Pnt>();
thePnt2 = aPoint2->impl<gp_Pnt>();
return true;
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
DEFINE_STANDARD_RTTI(SketcherPrs_LengthDimension)
+
+ /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ /// \return boolean result value
+ static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
protected:
/// Redefinition of virtual function
Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
const Standard_Integer aMode);
private:
- bool getPoints(gp_Pnt& thePnt1, gp_Pnt& thePnt2);
+ static bool getPoints(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane,
+ gp_Pnt& thePnt1, gp_Pnt& thePnt2);
/// Constraint feature
ModelAPI_Feature* myConstraint;
{
}
-
-bool SketcherPrs_Mirror::updatePoints(double theStep) const
+bool SketcherPrs_Mirror::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
{
+ bool aReadyToDisplay = false;
+
// Get axis of mirror
- ObjectPtr aAxisObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+ ObjectPtr aAxisObj = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
if (SketcherPrs_Tools::getShape(aAxisObj).get() == NULL)
- return false;
+ return aReadyToDisplay;
- std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
+ std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
// Get source objects
std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
if (anAttrB.get() == NULL)
- return false;
+ return aReadyToDisplay;
// Get mirrored objects
std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
if (anAttrC.get() == NULL)
- return false;
+ return aReadyToDisplay;
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
int aNb = anAttrB->size();
// If size of source objects and mirrored ones is not equal then the constraint is not computed
if (aNb != anAttrC->size())
+ return aReadyToDisplay;
+
+ aReadyToDisplay = true;
+ return aReadyToDisplay;
+}
+
+bool SketcherPrs_Mirror::updatePoints(double theStep) const
+{
+ if (!IsReadyToDisplay(myConstraint, myPlane))
return false;
+ // Get axis of mirror
+ ObjectPtr aAxisObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+
+ std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
+ // Get source objects
+ std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
+ // Get mirrored objects
+ std::shared_ptr<ModelAPI_AttributeRefList> anAttrC = aData->reflist(SketchPlugin_Constraint::ENTITY_C());
+
+ SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
+ int aNb = anAttrB->size();
+
myPntArray = new Graphic3d_ArrayOfPoints(2 * aNb);
int i;
ObjectPtr aObj;
Standard_EXPORT SketcherPrs_Mirror(ModelAPI_Feature* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
DEFINE_STANDARD_RTTI(SketcherPrs_Mirror)
+
+ /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ /// \return boolean result value
+ static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
protected:
virtual const char* iconName() const { return "mirror.png"; }
myPntArray->AddVertex(0., 0., 0.);
}
+bool SketcherPrs_Parallel::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
+{
+ bool aReadyToDisplay = false;
+
+ ObjectPtr aObj1 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
+ ObjectPtr aObj2 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B());
+
+ aReadyToDisplay = SketcherPrs_Tools::getShape(aObj1).get() != NULL &&
+ SketcherPrs_Tools::getShape(aObj2).get() != NULL;
+ return aReadyToDisplay;
+}
bool SketcherPrs_Parallel::updatePoints(double theStep) const
{
+ if (!IsReadyToDisplay(myConstraint, myPlane))
+ return false;
+
ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
- if (SketcherPrs_Tools::getShape(aObj1).get() == NULL)
- return false;
- if (SketcherPrs_Tools::getShape(aObj2).get() == NULL)
- return false;
// Compute position of symbols
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
Standard_EXPORT SketcherPrs_Parallel(ModelAPI_Feature* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
DEFINE_STANDARD_RTTI(SketcherPrs_Parallel)
+
+ /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ /// \return boolean result value
+ static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
protected:
virtual const char* iconName() const { return "parallel.png"; }
myPntArray->AddVertex(0., 0., 0.);
}
+bool SketcherPrs_Perpendicular::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
+{
+ bool aReadyToDisplay = false;
+
+ ObjectPtr aObj1 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
+ ObjectPtr aObj2 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B());
+
+ aReadyToDisplay = SketcherPrs_Tools::getShape(aObj1).get() != NULL &&
+ SketcherPrs_Tools::getShape(aObj2).get() != NULL;
+ return aReadyToDisplay;
+}
bool SketcherPrs_Perpendicular::updatePoints(double theStep) const
{
+ if (!IsReadyToDisplay(myConstraint, myPlane))
+ return false;
+
ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
- if (SketcherPrs_Tools::getShape(aObj1).get() == NULL)
- return false;
- if (SketcherPrs_Tools::getShape(aObj2).get() == NULL)
- return false;
// Compute position of symbols
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
DEFINE_STANDARD_RTTI(SketcherPrs_Perpendicular)
+
+ /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ /// \return boolean result value
+ static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
protected:
virtual const char* iconName() const { return "perpendicular.png"; }
SetSelToleranceForText2d(SketcherPrs_Tools::getDefaultTextHeight());
}
-void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
- const Handle(Prs3d_Presentation)& thePresentation,
- const Standard_Integer theMode)
+bool SketcherPrs_Radius::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
{
- DataPtr aData = myConstraint->data();
+ bool aReadyToDisplay = false;
+
+ DataPtr aData = theConstraint->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()) {
- Events_Error::throwException("An empty AIS presentation: SketcherPrs_Radius");
- return; // can not create a good presentation
+ return aReadyToDisplay; // can not create a good presentation
}
// Get circle
std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
- if (!anAttr) return;
+ if (!anAttr)
+ return aReadyToDisplay;
std::shared_ptr<ModelAPI_Feature> aCyrcFeature = ModelAPI_Feature::feature(anAttr->object());
double aRadius = 1;
// it is possible that circle result becomes zero, in this case the presentation should disappear
// for example, it happens when circle radius is set to zero
if (!aCyrcFeature)
+ return aReadyToDisplay;
+ 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 = thePlane->to3D(aCenterAttr->x(), aCenterAttr->y());
+ std::shared_ptr<GeomAPI_Dir> aNormal = thePlane->normal();
+
+ GeomAPI_Circ aCircle(aCenter, aNormal, aRadius);
+
+ std::shared_ptr<GeomAPI_Pnt> anAnchor = SketcherPrs_Tools::getAnchorPoint(theConstraint, thePlane);
+
+ gp_Circ aCirc = aCircle.impl<gp_Circ>();
+ gp_Pnt anAncorPnt = anAnchor->impl<gp_Pnt>();
+ // anchor point should not coincide to the location point of the circle
+ // OCCT does not process this case.
+
+ aReadyToDisplay = anAncorPnt.Distance(aCirc.Location()) > 1e-7;
+ return aReadyToDisplay;
+}
+
+void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
+{
+ if (!IsReadyToDisplay(myConstraint, myPlane)) {
+ Events_Error::throwException("An empty AIS presentation: SketcherPrs_Radius");
return;
+ }
+
+ 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()));
gp_Circ aCirc = aCircle.impl<gp_Circ>();
gp_Pnt anAncorPnt = anAnchor->impl<gp_Pnt>();
- // anchor point should not coincide to the location point of the circle
- // OCCT does not process this case.
- if (anAncorPnt.Distance(aCirc.Location()) < 1e-7)
- return;
+
SetMeasuredGeometry(aCirc, anAncorPnt);
SetCustomValue(aRadius);
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
DEFINE_STANDARD_RTTI(SketcherPrs_Radius)
+
+ /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ /// \return boolean result value
+ static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
protected:
/// Redefinition of virtual function
Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
myPntArray->AddVertex(0., 0., 0.);
}
+bool SketcherPrs_Rigid::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+{
+ bool aReadyToDisplay = false;
+
+ std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
+ std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = aData->refattr(SketchPlugin_Constraint::ENTITY_A());
+ AttributePtr aRefAttr = anAttr->attr();
+ if (anAttr->isObject()) {
+ // The constraint attached to an object
+ ObjectPtr aObj = anAttr->object();
+ aReadyToDisplay = SketcherPrs_Tools::getShape(aObj).get() != NULL;
+
+ } else {
+ // The constraint attached to a point
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theConstraint,
+ SketchPlugin_Constraint::ENTITY_A());
+ aReadyToDisplay = aPnt.get() != NULL;
+ }
+ return aReadyToDisplay;
+}
bool SketcherPrs_Rigid::updatePoints(double theStep) const
{
+ if (!IsReadyToDisplay(myConstraint, myPlane))
+ return false;
+
std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = aData->refattr(SketchPlugin_Constraint::ENTITY_A());
AttributePtr aRefAttr = anAttr->attr();
if (anAttr->isObject()) {
// The constraint attached to an object
ObjectPtr aObj = anAttr->object();
- if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
- return false;
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep);
myPntArray->SetVertice(1, aP1);
} else {
// The constraint attached to a point
- std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_A());
- if (aPnt.get() == NULL)
- return false;
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint,
+ SketchPlugin_Constraint::ENTITY_A());
std::shared_ptr<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y() + theStep);
myPntArray->SetVertice(1, aPoint->impl<gp_Pnt>());
}
DEFINE_STANDARD_RTTI(SketcherPrs_Rigid)
+
+ /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ /// \return boolean result value
+ static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
protected:
virtual const char* iconName() const { return "anchor.png"; }
myPntArray->AddVertex(0., 0., 0.);
}
+bool SketcherPrs_Tangent::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
+{
+ bool aReadyToDisplay = false;
+
+ ObjectPtr aObj1 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
+ ObjectPtr aObj2 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B());
+
+ aReadyToDisplay = SketcherPrs_Tools::getShape(aObj1).get() != NULL &&
+ SketcherPrs_Tools::getShape(aObj2).get() != NULL;
+
+ return aReadyToDisplay;
+}
+
bool SketcherPrs_Tangent::updatePoints(double theStep) const
{
ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
- if (SketcherPrs_Tools::getShape(aObj1).get() == NULL)
- return false;
- if (SketcherPrs_Tools::getShape(aObj2).get() == NULL)
- return false;
// Compute points coordinates
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
DEFINE_STANDARD_RTTI(SketcherPrs_Tangent)
+
+ /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ /// \return boolean result value
+ static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
protected:
virtual const char* iconName() const { return "tangent.png"; }
{
}
-bool SketcherPrs_Transformation::updatePoints(double theStep) const
+bool SketcherPrs_Transformation::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
{
- std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
+ bool aReadyToDisplay = false;
+
+ std::shared_ptr<ModelAPI_Data> aData = theConstraint->data();
// Get transformated objects list
std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
if (anAttrB.get() == NULL)
+ return aReadyToDisplay;
+
+ int aNbB = anAttrB->size();
+ aReadyToDisplay = aNbB > 0;
+ return aReadyToDisplay;
+}
+
+bool SketcherPrs_Transformation::updatePoints(double theStep) const
+{
+ if (!IsReadyToDisplay(myConstraint, myPlane))
return false;
+ std::shared_ptr<ModelAPI_Data> aData = myConstraint->data();
+ // Get transformated objects list
+ std::shared_ptr<ModelAPI_AttributeRefList> anAttrB = aData->reflist(SketchPlugin_Constraint::ENTITY_B());
+
int aNbB = anAttrB->size();
if (aNbB == 0)
{
//if (!myPntArray.IsNull())
// mySPoints.Clear();
#endif
- return false;
}
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
bool isTranslation);
DEFINE_STANDARD_RTTI(SketcherPrs_Transformation)
+
+ /// Returns true if the constraint feature arguments are correcly filled to build AIS presentation
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ /// \return boolean result value
+ static bool IsReadyToDisplay(ModelAPI_Feature* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
protected:
virtual const char* iconName() const { return myIsTranslation? "translate.png" : "rotate.png"; }