+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
// File: SketchPlugin_ConstraintLength.cpp
// Created: 30 May 2014
// Author: Artem ZHIDKOV
//if(!aValueAttr->isInitialized()) {
// aValueAttr->setValue(aLenght);
//}
+
+ // the value should to be computed here, not in the getAISObject in order to change the model value
+ // inside the object transaction. This is important for creating a constraint by preselection.
+ // The display of the presentation in this case happens after the transaction commit
+ AttributePtr aFlyOutAttribute = data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
+ if (!aFlyOutAttribute->isInitialized()) {
+ compute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
+ }
}
}
+bool SketchPlugin_ConstraintLength::compute(const std::string& theAttributeId)
+{
+ if (theAttributeId != SketchPlugin_Constraint::FLYOUT_VALUE_PNT())
+ return false;
+
+ std::shared_ptr<GeomAPI_Pnt> aPoint1, aPoint2;
+ std::shared_ptr<GeomDataAPI_Point2D> aStartPoint, anEndPoint;
+ if (!getPoints(aPoint1, aPoint2, aStartPoint, anEndPoint))
+ return false;
+
+ std::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = std::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(data()->attribute(theAttributeId));
+
+ std::shared_ptr<GeomAPI_Lin2d> aLine =
+ std::shared_ptr<GeomAPI_Lin2d>(new GeomAPI_Lin2d(aStartPoint->pnt(), anEndPoint->pnt()));
+ double aDist = aPoint1->distance(aPoint2)/5.;
+ std::shared_ptr<GeomAPI_Pnt2d> aFPnt = aLine->shiftedLocation(aDist);
+ aFlyOutAttr->setValue(aFPnt);
+
+ return true;
+}
+
bool SketchPlugin_ConstraintLength::getPoints(
std::shared_ptr<GeomAPI_Pnt>& thePoint1, std::shared_ptr<GeomAPI_Pnt>& thePoint2,
std::shared_ptr<GeomDataAPI_Point2D>& theStartPoint,
if (!getPoints(aPoint1, aPoint2, aStartPoint, anEndPoint))
return thePrevious; // not possible to show length because points are not defined
- std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
- std::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
- std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = std::shared_ptr<GeomAPI_Pnt>();
- if (aFlyOutAttr->isInitialized()) {
- aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y());
- } else {
- std::shared_ptr<GeomAPI_Lin2d> aLine =
- std::shared_ptr<GeomAPI_Lin2d>(new GeomAPI_Lin2d(aStartPoint->pnt(), anEndPoint->pnt()));
- double aDist = aPoint1->distance(aPoint2)/5.;
- std::shared_ptr<GeomAPI_Pnt2d> aFPnt = aLine->shiftedLocation(aDist);
- aFlyOutAttr->setValue(aFPnt);
- aFlyoutPnt = sketch()->to3D(aFPnt->x(), aFPnt->y());
+ 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);
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);
// Set color from preferences
- std::vector<int> aRGB =
- Config_PropManager::color("Visualization", "length_color", LENGTH_COLOR);
+ std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_dimension_color",
+ SKETCH_DIMENSION_COLOR);
anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}