QGridLayout* aGroupLay = new QGridLayout(myGroupBox);
ModuleBase_Tools::adjustMargins(aGroupLay);
+ aGroupLay->setSpacing(2);
aGroupLay->setColumnStretch(1, 1);
{
QLabel* aLabel = new QLabel(myGroupBox);
- aLabel->setText(tr("X"));
- aLabel->setPixmap(QPixmap(":pictures/x_point.png"));
+ aLabel->setText(tr("X "));
aGroupLay->addWidget(aLabel, 0, 0);
myXSpin = new ModuleBase_ParamSpinBox(myGroupBox);
}
{
QLabel* aLabel = new QLabel(myGroupBox);
- aLabel->setText(tr("Y"));
- aLabel->setPixmap(QPixmap(":pictures/y_point.png"));
+ aLabel->setText(tr("Y "));
aGroupLay->addWidget(aLabel, 1, 0);
myYSpin = new ModuleBase_ParamSpinBox(myGroupBox);
setLayout(aLayout);
}
-void PartSet_WidgetPoint2D::reset()
+bool PartSet_WidgetPoint2D::reset()
{
- if (!isUseReset())
- return;
-
- if (isComputedDefault() || myXSpin->hasVariable() || myYSpin->hasVariable()) {
- return;
- //if (myFeature->compute(myAttributeID))
- // restoreValue();
+ bool aDone = false;
+ if (!isUseReset() || isComputedDefault() || myXSpin->hasVariable() || myYSpin->hasVariable()) {
+ aDone = false;
}
else {
bool isOk;
ModuleBase_Tools::setSpinValue(myXSpin, isOk ? aDefValue : 0.0);
ModuleBase_Tools::setSpinValue(myYSpin, isOk ? aDefValue : 0.0);
storeValueCustom();
+ aDone = true;
}
+ return aDone;
}
PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D()
{
}
-bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrs>& theValues)
+bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
+ const bool theToValidate)
{
if (theValues.empty())
return false;
PartSet_WidgetPoint2D* that = (PartSet_WidgetPoint2D*) this;
bool isBlocked = that->blockSignals(true);
bool isImmutable = aPoint->setImmutable(true);
-
- if (myXSpin->hasVariable() || myYSpin->hasVariable()) {
- aPoint->setText(myXSpin->text().toStdString(), myYSpin->text().toStdString());
- } else {
- aPoint->setValue(myXSpin->value(), myYSpin->value());
- aPoint->setText("", "");
- }
+
+ // if text is not empty then setValue will be ignored
+ // so we should set the text at first
+ aPoint->setText(myXSpin->hasVariable() ? myXSpin->text().toStdString() : "",
+ myYSpin->hasVariable() ? myYSpin->text().toStdString() : "");
+ aPoint->setValue(!myXSpin->hasVariable() ? myXSpin->value() : aPoint->x(),
+ !myYSpin->hasVariable() ? myYSpin->value() : aPoint->y());
+
// after movement the solver will call the update event: optimization
moveObject(myFeature);
aPoint->setImmutable(isImmutable);
return true;
}
-bool PartSet_WidgetPoint2D::restoreValue()
+bool PartSet_WidgetPoint2D::restoreValueCustom()
{
std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
aData->attribute(attributeID()));
- std::string aTextX = aPoint->textX();
- std::string aTextY = aPoint->textY();
- if (aTextX.empty() || aTextY.empty()) {
- double aX = aPoint->x();
+ QString aTextX = QString::fromStdString(aPoint->textX());
+ QString aTextY = QString::fromStdString(aPoint->textY());
+
+ bool isDouble = false;
+ double aVal = 0;
+ if (aTextX.isEmpty()) {
ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x());
+ } else {
+ aVal = aTextX.toDouble(&isDouble);
+ if (isDouble)
+ ModuleBase_Tools::setSpinValue(myXSpin, aVal);
+ else
+ ModuleBase_Tools::setSpinText(myXSpin, aTextX);
+ }
+ if (aTextY.isEmpty()) {
ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y());
} else {
- ModuleBase_Tools::setSpinText(myXSpin, QString::fromStdString(aTextX));
- ModuleBase_Tools::setSpinText(myYSpin, QString::fromStdString(aTextY));
+ aVal = aTextY.toDouble(&isDouble);
+ if (isDouble)
+ ModuleBase_Tools::setSpinValue(myYSpin, aVal);
+ else
+ ModuleBase_Tools::setSpinText(myYSpin, aTextY);
}
+ //if (aTextX.empty() || aTextY.empty()) {
+ // ModuleBase_Tools::setSpinValue(myXSpin, aPoint->x());
+ // ModuleBase_Tools::setSpinValue(myYSpin, aPoint->y());
+ //} else {
+ // ModuleBase_Tools::setSpinText(myXSpin, QString::fromStdString(aTextX));
+ // ModuleBase_Tools::setSpinText(myYSpin, QString::fromStdString(aTextY));
+ //}
return true;
}
return false;
}
+void PartSet_WidgetPoint2D::setConstraintWith(const ObjectPtr& theObject)
+{
+ // Create point-edge coincedence
+ FeaturePtr aFeature = mySketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+ std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
+
+ std::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 = std::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
+ AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
+ std::shared_ptr<GeomDataAPI_Point2D> aThisPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
+ aRef1->setAttr(aThisPoint);
+
+ std::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 = std::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
+ aRef2->setObject(theObject);
+
+ aFeature->execute();
+}
void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
if ((!aSPFeature) && (!aShape.IsNull())) {
ResultPtr aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aObject, mySketch);
if (!aFixedObject.get())
- aFixedObject = PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
+ aObject = PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
+ setConstraintWith(aObject);
+ emit vertexSelected();
+ emit focusOutWidget(this);
+ return;
}
}
double aX, aY;
+ bool isProcessed = false;
if (getPoint2d(aView, aShape, aX, aY)) {
- setPoint(aX, aY);
-
PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
- emit vertexSelected();
- emit focusOutWidget(this);
- return;
+ isProcessed = true;
} else if (aShape.ShapeType() == TopAbs_EDGE) {
- // Create point-edge coincedence
- FeaturePtr aFeature = mySketch->addFeature(SketchPlugin_ConstraintCoincidence::ID());
- std::shared_ptr<ModelAPI_Data> aData = aFeature->data();
-
- std::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 = std::dynamic_pointer_cast<
- ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
- AttributePtr aThisAttr = feature()->data()->attribute(attributeID());
- std::shared_ptr<GeomDataAPI_Point2D> aThisPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aThisAttr);
- aRef1->setAttr(aThisPoint);
-
- std::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 = std::dynamic_pointer_cast<
- ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRef2->setObject(aObject);
- aFeature->execute();
+ setConstraintWith(aObject);
+ isProcessed = true;
+ }
+ if (isProcessed) {
+ // it is important to perform updateObject() in order to the current value is
+ // processed by Sketch Solver. Test case: line is created from a previous point
+ // to some distance, but in the area of the highlighting of the point. Constraint
+ // coincidence is created, after the solver is performed, the distance between the
+ // points of the line becomes less than the tolerance. Validator of the line returns
+ // false, the line will be aborted, but sketch stays valid.
+ updateObject(feature());
emit vertexSelected();
emit focusOutWidget(this);
return;