From db1e462ad6a76ee857f47602ec9acba6315529c8 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 25 Jun 2014 11:14:11 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc 1. Property panel input correction for a feature creation. It was not possible to perform "apply" 2. Creation opertion - do not allow to activate the next widget if the previous is not processed. Error: create arc, start lenght feature creation, select arc, the result is an editor control with the zero value inside. --- src/ModuleBase/ModuleBase_ModelWidget.cpp | 8 +++ src/ModuleBase/ModuleBase_ModelWidget.h | 5 ++ .../PartSet_OperationFeatureCreate.cpp | 6 +- src/SketchPlugin/SketchPlugin_Arc.cpp | 64 ++++++++++--------- src/XGUI/XGUI_OperationMgr.cpp | 8 +-- src/XGUI/XGUI_PropertyPanel.cpp | 5 ++ src/XGUI/XGUI_PropertyPanel.h | 1 + src/XGUI/XGUI_Workshop.cpp | 24 ++++++- src/XGUI/XGUI_Workshop.h | 2 + 9 files changed, 83 insertions(+), 40 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index a15c0edcc..cd56f06c3 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -4,6 +4,9 @@ #include "ModuleBase_ModelWidget.h" +#include +#include + #include "Config_WidgetAPI.h" #include @@ -14,6 +17,11 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, const Config_ myAttributeID = theData ? theData->widgetId() : ""; } +bool ModuleBase_ModelWidget::isInitialized(FeaturePtr theFeature) const +{ + return theFeature->data()->attribute(attributeID())->isInitialized(); +} + bool ModuleBase_ModelWidget::canFocusTo(const std::string& theAttributeName) const { return theAttributeName == attributeID(); diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 4bb40e362..78680ec3b 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -36,6 +36,11 @@ public: /// Destructor virtual ~ModuleBase_ModelWidget() {}; + /// Returns the state whether the attribute of the feature is initialized + /// \param theFeature a model feature to be checked + /// \return the boolean result + bool isInitialized(FeaturePtr theFeature) const; + /// Saves the internal parameters to the given feature /// \param theFeature a model feature to be changed virtual bool storeValue(FeaturePtr theFeature) const = 0; diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index ec146ba79..5b22f3fac 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -167,8 +167,10 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle isApplyed = setWidgetFeature(aFeature); } } - flushUpdated(); - emit activateNextWidget(myActiveWidget); + if (isApplyed) { + flushUpdated(); + emit activateNextWidget(myActiveWidget); + } } void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index ed8d3be22..c0891d80d 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -43,42 +43,44 @@ const boost::shared_ptr& SketchPlugin_Arc::preview() // compute a circle point in 3D view boost::shared_ptr aCenterAttr = boost::dynamic_pointer_cast(data()->attribute(ARC_ATTR_CENTER)); - boost::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); - // make a visible point - boost::shared_ptr aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter); - aShapes.push_back(aCenterPointShape); - - // make a visible circle - boost::shared_ptr aNDir = - boost::dynamic_pointer_cast(aSketch->data()->attribute(SKETCH_ATTR_NORM)); - bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0); - if (aHasPlane) { - boost::shared_ptr aNormal = aNDir->dir(); // compute the arc start point boost::shared_ptr aStartAttr = boost::dynamic_pointer_cast(data()->attribute(ARC_ATTR_START)); - boost::shared_ptr aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y())); - - // compute and change the arc end point - boost::shared_ptr anEndAttr = - boost::dynamic_pointer_cast(data()->attribute(ARC_ATTR_END)); - if (anEndAttr->isInitialized()) - { - boost::shared_ptr aCircleForArc( - new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt())); - boost::shared_ptr aProjection = aCircleForArc->project(anEndAttr->pnt()); - if (aProjection && anEndAttr->pnt()->distance(aProjection) > Precision::Confusion()) - anEndAttr->setValue(aProjection); + if (aCenterAttr->isInitialized() && aStartAttr->isInitialized()) { + boost::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); + // make a visible point + boost::shared_ptr aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter); + aShapes.push_back(aCenterPointShape); + + // make a visible circle + boost::shared_ptr aNDir = + boost::dynamic_pointer_cast(aSketch->data()->attribute(SKETCH_ATTR_NORM)); + bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0); + if (aHasPlane) { + boost::shared_ptr aNormal = aNDir->dir(); + boost::shared_ptr aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y())); + + // compute and change the arc end point + boost::shared_ptr anEndAttr = + boost::dynamic_pointer_cast(data()->attribute(ARC_ATTR_END)); + if (anEndAttr->isInitialized()) + { + boost::shared_ptr aCircleForArc( + new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt())); + boost::shared_ptr aProjection = aCircleForArc->project(anEndAttr->pnt()); + if (aProjection && anEndAttr->pnt()->distance(aProjection) > Precision::Confusion()) + anEndAttr->setValue(aProjection); + } + boost::shared_ptr aEndPoint(aSketch->to3D(anEndAttr->x(), anEndAttr->y())); + + boost::shared_ptr aCircleShape = + GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStartPoint, aEndPoint, aNormal); + if (aCircleShape) + aShapes.push_back(aCircleShape); } - boost::shared_ptr aEndPoint(aSketch->to3D(anEndAttr->x(), anEndAttr->y())); - - boost::shared_ptr aCircleShape = - GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStartPoint, aEndPoint, aNormal); - if (aCircleShape) - aShapes.push_back(aCircleShape); + boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes); + setPreview(aCompound); } - boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes); - setPreview(aCompound); } return getPreview(); } diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 320678b14..49faabba5 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -117,12 +117,8 @@ bool XGUI_OperationMgr::canStopOperation() void XGUI_OperationMgr::onCommitOperation() { ModuleBase_Operation* anOperation = currentOperation(); - if (anOperation) { - if (anOperation->canBeCommitted()) - anOperation->commit(); - else - anOperation->abort(); - } + if (anOperation) + anOperation->commit(); } void XGUI_OperationMgr::onAbortOperation() diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 54933b4b2..ae3df8179 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -122,6 +122,11 @@ void XGUI_PropertyPanel::setModelWidgets(const QList& t } } +const QList& XGUI_PropertyPanel::modelWidgets() const +{ + return myWidgets; +} + bool XGUI_PropertyPanel::eventFilter(QObject *theObject, QEvent *theEvent) { QPushButton* anOkBtn = findChild(XGUI::PROP_PANEL_OK); diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index 51155a481..764575dd8 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -27,6 +27,7 @@ public: QWidget* contentWidget(); void setModelWidgets(const QList& theWidgets); + const QList& modelWidgets() const; void cleanContent(); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index eb099c9b7..3b5068dfa 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -322,7 +322,9 @@ void XGUI_Workshop::onOperationStarted() ModuleBase_ModelWidget* aWidget; for (; anIt != aLast; anIt++) { aWidget = *anIt; - QObject::connect(aWidget, SIGNAL(valuesChanged()), aOperation, SLOT(storeCustomValue())); + //QObject::connect(aWidget, SIGNAL(valuesChanged()), aOperation, SLOT(storeCustomValue())); + QObject::connect(aWidget, SIGNAL(valuesChanged()), + this, SLOT(onWidgetValuesChanged())); // Init default values if (!aOperation->isEditOperation() && aWidget->hasDefaultValue()) { aWidget->storeValue(aOperation->feature()); @@ -823,6 +825,26 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) showFeatures(aFeatures, false); } +//************************************************************** +void XGUI_Workshop::onWidgetValuesChanged() +{ + ModuleBase_Operation* anOperation = myOperationMgr->currentOperation(); + FeaturePtr aFeature = anOperation->feature(); + + ModuleBase_ModelWidget* aSenderWidget = dynamic_cast(sender()); + //if (aCustom) + // aCustom->storeValue(aFeature); + + const QList& aWidgets = myPropertyPanel->modelWidgets(); + QList::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end(); + for (; anIt != aLast; anIt++) { + ModuleBase_ModelWidget* aCustom = *anIt; + if (aCustom && (!aCustom->isInitialized(aFeature) || aCustom == aSenderWidget)) { + aCustom->storeValue(aFeature); + } + } +} + //************************************************************** void XGUI_Workshop::activatePart(FeaturePtr theFeature) { diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index fba793e83..e52f48db8 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -155,6 +155,8 @@ protected slots: void onContextMenuCommand(const QString& theId, bool isChecked); + void onWidgetValuesChanged(); + private: void initMenu(); -- 2.39.2