Length constraint.
ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
{
- //delete myEditor;
}
bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const
{
DataPtr aData = theFeature->data();
AttributeDoublePtr aReal = aData->real(attributeID());
- bool isOk;
- if (isOk && aReal->value() != myValue) {
+ if (aReal->value() != myValue) {
aReal->setValue(myValue);
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
}
if (aRes == QDialog::Accepted)
myValue = aEditor->text().toDouble();
+ emit valuesChanged();
emit focusOutWidget(this);
}
if (!aFeatureLin->isRight(aPoint))
aDistance = -aDistance;
- AttributeDoublePtr aFlyoutAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
- aFlyoutAttr->setValue(aDistance);
+ //AttributeDoublePtr aFlyoutAttr =
+ // boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
+ //aFlyoutAttr->setValue(aDistance);
aMode = SM_DonePoint;
}
boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>
(new GeomAPI_Pnt2d(theX, theY));
- PartSet_Tools::setFeaturePoint(feature(), theX, theY, SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT);
+ //PartSet_Tools::setFeaturePoint(feature(), theX, theY, SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT);
//double aDistance = 40;
//AttributeDoublePtr aFlyoutAttr =
return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND ||
theId == SKETCH_CIRCLE_KIND /*||
theId == SKETCH_ARC_KIND*/ ||
- theId == SKETCH_CONSTRAINT_DISTANCE_KIND /*||
+ theId == SKETCH_CONSTRAINT_DISTANCE_KIND ||
theId == SKETCH_CONSTRAINT_LENGTH_KIND ||
- theId == SKETCH_CONSTRAINT_RADIUS_KIND ||
+ theId == SKETCH_CONSTRAINT_RADIUS_KIND /*||
theId == SKETCH_CONSTRAINT_PARALLEL_KIND ||
theId == SKETCH_CONSTRAINT_PERPENDICULAR_KIND*/;
}
const std::string CONSTRAINT_ATTR_VALUE("ConstraintValue");
/// The 2D value parameter for the constraint
const std::string CONSTRAINT_ATTR_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
-/// The value parameter for the constraint
-const std::string CONSTRAINT_ATTR_FLYOUT_VALUE("ConstraintFlyoutValue");
/// First entity for the constraint
const std::string CONSTRAINT_ATTR_ENTITY_A("ConstraintEntityA");
/// Second entity for the constraint
boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin =
boost::shared_ptr<GeomAPI_Lin2d>(new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(),
aPoint_B->x(), aPoint_B->y()));
- boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aFlyOutPnt);
- double aDistance = aFlyOutPnt->distance(aResult);
-
+ boost::shared_ptr<GeomAPI_Pnt2d> aProjectedPoint = aFeatureLin->project(aFlyOutPnt);
+ double aDistance = aFlyOutPnt->distance(aProjectedPoint);
if (!aFeatureLin->isRight(aFlyOutPnt))
aDistance = -aDistance;
double aFlyout = aDistance;
//Build dimension here
boost::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aPoint_A->x(), aPoint_A->y());
boost::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(aPoint_B->x(), aPoint_B->y());
- if (aFlyout < 0)
- aPoint1.swap(aPoint2);
// value calculation
boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
double aValue = aValueAttr->value();
- if (aValue == 0) { // TODO! the default value
- aValue = aPoint1->distance(aPoint2);
- }
Handle(AIS_InteractiveObject) anAIS = thePrevious;
if (anAIS.IsNull())
#include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Lin2d.h>
+#include <GeomAPI_Pnt2d.h>
+
#include <AIS_LengthDimension.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pln.hxx>
void SketchPlugin_ConstraintLength::initAttributes()
{
data()->addAttribute(CONSTRAINT_ATTR_VALUE, ModelAPI_AttributeDouble::type());
- data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type());
+ //data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type());
data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
}
void SketchPlugin_ConstraintLength::execute()
{
+ if (data()->attribute(CONSTRAINT_ATTR_ENTITY_A)->isInitialized() &&
+ !data()->attribute(CONSTRAINT_ATTR_VALUE)->isInitialized()) {
+
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ FeaturePtr aFeature = aRef->feature();
+ if (aFeature) {
+ // set length value
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(LINE_ATTR_START));
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(LINE_ATTR_END));
+
+ double aLenght = aPoint1->pnt()->distance(aPoint2->pnt());
+
+ boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_VALUE));
+ aValueAttr->setValue(aLenght);
+ }
+ }
}
Handle(AIS_InteractiveObject) SketchPlugin_ConstraintLength::getAISShape(
if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND)
return thePrevious;
- boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
- double aFlyout = aFlyoutAttr->value();
-
+ //boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr =
+ // boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
+ //double aFlyout = aFlyoutAttr->value();
+ // fly out calculation
+ boost::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+ boost::shared_ptr<GeomAPI_Pnt2d> aFlyOutPnt = aFlyOutAttr->pnt();
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aStartPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(LINE_ATTR_START));
+ boost::shared_ptr<GeomDataAPI_Point2D> anEndPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(LINE_ATTR_END));
+
+ boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = boost::shared_ptr<GeomAPI_Lin2d>
+ (new GeomAPI_Lin2d(aStartPoint->x(), aStartPoint->y(),
+ anEndPoint->x(), anEndPoint->y()));
+ boost::shared_ptr<GeomAPI_Pnt2d> aProjectedPoint = aFeatureLin->project(aFlyOutPnt);
+ double aDistance = aFlyOutPnt->distance(aProjectedPoint);
+ if (!aFeatureLin->isRight(aFlyOutPnt))
+ aDistance = -aDistance;
+ double aFlyout = aDistance;
+
+ // value
boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_VALUE));
double aValue = aValueAttr->value();
//Build dimension here
boost::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aPointStart->x(), aPointStart->y());
boost::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(aPointEnd->x(), aPointEnd->y());
- if (aFlyout < 0)
- aPoint1.swap(aPoint2);
Handle(AIS_InteractiveObject) anAIS = thePrevious;
if (anAIS.IsNull())
{
data()->addAttribute(CONSTRAINT_ATTR_VALUE, ModelAPI_AttributeDouble::type());
data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
-
- data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type());
- data()->addAttribute(SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT, GeomDataAPI_Point2D::type());
+ data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
}
void SketchPlugin_ConstraintRadius::execute()
{
+
}
Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape(
// an anchor point
boost::shared_ptr<GeomDataAPI_Point2D> aAnchorAttr =
- boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT));
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
boost::shared_ptr<GeomAPI_Pnt2d> anAnchor2D = aAnchorAttr->pnt();
boost::shared_ptr<GeomAPI_Pnt> anAnchor = sketch()->to3D(anAnchor2D->x(), anAnchor2D->y());
/// Radius constraint kind
const std::string SKETCH_CONSTRAINT_RADIUS_KIND("SketchConstraintRadius");
-/// Start 2D point of the line
-const std::string SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT("CirclePoint");
-
-
/** \class SketchPlugin_ConstraintRadius
* \ingroup DataModel
* \brief Feature for creation of a new constraint which defines
<feature id="SketchConstraintRadius" title="Radius of a circle or an arc" tooltip="Create constraint for the given radius of a circle or an arc">
<label title="Select two points on a circle or an arc of circle on which to calculate radius" tooltip="Select two points on a circle or an arc of circle on which to calculate radius"/>
<feature_selector id="ConstraintEntityA" keysequence="SketchPoint" internal="1"/>
- <point_selector id="CirclePoint" internal="1"/>
+ <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
<doublevalue_editor id="ConstraintValue"/>
</feature>
<feature id="SketchConstraintParallel" title="Parallelism of a lines" tooltip="Create constraint defining two parallel lines">