protected:
/// Update focus after the attribute value change
- virtual void updateFocus() = 0;
+ virtual void updateFocus() {};
/// Return the attribute values wrapped in a list of viewer presentations
/// \return a list of viewer presentations, which contains an attribute result and
/// a shape. If the attribute do not uses the shape, it is empty
- virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const = 0;
+ virtual QList<ModuleBase_ViewerPrs> getAttributeSelection() const;
/// Retunrs a list of possible shape types
/// \return a list of shapes
virtual QIntList getShapeTypes() const = 0;
/// Computes and updates name of selected object in the widget
- virtual void updateSelectionName() = 0;
+ virtual void updateSelectionName() {};
/// Store the values to the model attribute of the widget. It casts this attribute to
/// the specific type and set the given values
/// \param theSelectedObject an object
/// \param theShape a selected shape, which is used in the selection attribute
/// \return true if it is succeed
- virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) = 0;
+ virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) {};
/// The methiod called when widget is activated
virtual void activateCustom();
#include <XGUI_Displayer.h>
#include <XGUI_SelectionMgr.h>
#include <XGUI_OperationMgr.h>
+#include <XGUI_PropertyPanel.h>
#include <GeomAPI_Face.h>
#include <QLabel>
#include <QLineEdit>
-#include <QFormLayout>
+//#include <QFormLayout>
+#include <QVBoxLayout>
#include <QMessageBox>
PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent,
PartSet_Module* theModule,
const Config_WidgetAPI* theData)
-: ModuleBase_ModelWidget(theParent, theData), myModule(theModule), myUseBody(true)
+: ModuleBase_WidgetSelector(theParent, theModule->workshop(), theData),
+ myModule(theModule), myUseBody(true)
{
- QFormLayout* aLayout = new QFormLayout(this);
+ myAttributeListID = theData->getProperty("attribute_list_id");
+
+ //QFormLayout* aLayout = new QFormLayout(this);
+ QVBoxLayout* aLayout = new QVBoxLayout(this);
+ ModuleBase_Tools::zeroMargins(aLayout);
+
ModuleBase_Tools::adjustMargins(aLayout);
QString aLabelText = QString::fromStdString(theData->widgetLabel());
QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+
myLabel = new QLabel(aLabelText, this);
- if (!aLabelIcon.isEmpty())
+ myLabel->setWordWrap(true);
+ aLayout->addWidget(myLabel);
+ /*if (!aLabelIcon.isEmpty())
myLabel->setPixmap(QPixmap(aLabelIcon));
myUseBody = QVariant(aUseBody).toBool();
}
- aLayout->addRow(myLabel, myTextLine);
+ aLayout->addRow(myLabel, myTextLine);*/
+
+ std::string aTypes = theData->getProperty("shape_types");
+ myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts);
}
PartSet_WidgetSketchCreator::~PartSet_WidgetSketchCreator()
QList<QWidget*> PartSet_WidgetSketchCreator::getControls() const
{
QList<QWidget*> aControls;
- aControls.append(myTextLine);
+ aControls.append(myLabel);
return aControls;
}
bool PartSet_WidgetSketchCreator::restoreValueCustom()
{
- CompositeFeaturePtr aCompFeature =
+ /*CompositeFeaturePtr aCompFeature =
std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
if (aCompFeature->numberOfSubs() > 0) {
FeaturePtr aSubFeature = aCompFeature->subFeature(0);
myTextLine->setText(QString::fromStdString(aSubFeature->data()->name()));
- }
+ }*/
return true;
}
void PartSet_WidgetSketchCreator::activateCustom()
{
- CompositeFeaturePtr aCompFeature =
- std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
- if (aCompFeature->numberOfSubs() == 0)
- connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
+ if (isSelectionMode()) {
+ ModuleBase_WidgetSelector::activateCustom();
+ //connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
+
+ //setVisibleSelectionControl(true);
+ }
+ else {
+ setVisibleSelectionControl(false);
+ emit focusOutWidget(this);
+ }
+}
+
+void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelectionControl)
+{
+ // hide current widget, activate the next widget
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
+ XGUI_PropertyPanel* aPanel = aWorkshop->propertyPanel();
+ const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
+ foreach(ModuleBase_ModelWidget* aWidget, aWidgets) {
+ if (theSelectionControl) { // hide other controls
+ if (aWidget != this)
+ aWidget->setVisible(false);
+ }
+ else { // hide current control
+ if (aWidget == this)
+ aWidget->setVisible(false);
+ }
+ }
+}
+
+QIntList PartSet_WidgetSketchCreator::getShapeTypes() const
+{
+ QIntList aShapeTypes;
+ foreach(QString aType, myShapeTypes) {
+ aShapeTypes.append(ModuleBase_Tools::shapeType(aType));
+ }
+ return aShapeTypes;
+}
+
+void PartSet_WidgetSketchCreator::deactivate()
+{
+ if (isSelectionMode()) {
+ ModuleBase_WidgetSelector::activateCustom();
+ }
+}
+
+bool PartSet_WidgetSketchCreator::isSelectionMode() const
+{
+ //CompositeFeaturePtr aCompFeature =
+ // std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+ //bool aHasSub = aCompFeature->numberOfSubs() > 0;
+
+ AttributeSelectionListPtr anAttrList = myFeature->data()->selectionList(myAttributeListID);
+ bool aHasValueInList = anAttrList.get() && anAttrList->size() > 0;
+
+ return !aHasValueInList;//aHasSub || aHasValueInList;
}
void PartSet_WidgetSketchCreator::onStarted()
{
disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted()));
+ setVisibleSelectionControl(true);
+
+ /*
// Check that model already has bodies
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
XGUI_Workshop* aWorkshop = aConnector->workshop();
tr("There are no bodies found. Operation aborted."), QMessageBox::Ok);
ModuleBase_Operation* aOp = myModule->workshop()->currentOperation();
aOp->abort();
- }
+ }*/
}
bool PartSet_WidgetSketchCreator::focusTo()
{
- CompositeFeaturePtr aCompFeature =
- std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
- if (aCompFeature->numberOfSubs() == 0)
- return ModuleBase_ModelWidget::focusTo();
-
- connect(myModule, SIGNAL(resumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*)));
- SessionPtr aMgr = ModelAPI_Session::get();
- // Open transaction that is general for the previous nested one: it will be closed on nested commit
- bool aIsOp = aMgr->isOperation();
- if (!aIsOp) {
- const static std::string aNestedOpID("Parameters modification");
- aMgr->startOperation(aNestedOpID, true);
+ if (isSelectionMode()) {
+ //CompositeFeaturePtr aCompFeature =
+ // std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+ // if (aCompFeature->numberOfSubs() == 0)
+ // return ModuleBase_ModelWidget::focusTo();
+ connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
+ return true;
+ }
+ else {
+ connect(myModule, SIGNAL(resumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*)));
+ SessionPtr aMgr = ModelAPI_Session::get();
+ // Open transaction that is general for the previous nested one: it will be closed on nested commit
+ bool aIsOp = aMgr->isOperation();
+ if (!aIsOp) {
+ const static std::string aNestedOpID("Parameters modification");
+ aMgr->startOperation(aNestedOpID, true);
+ }
+ restoreValue();
}
-
- restoreValue();
return false;
}
#include "PartSet.h"
-#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_WidgetSelector.h>
class QLabel;
class QLineEdit;
* it will transfer a focus to next widget. It is supposed that the widget will be placed as
* a first widget in property panel
*/
-class PARTSET_EXPORT PartSet_WidgetSketchCreator : public ModuleBase_ModelWidget
+class PARTSET_EXPORT PartSet_WidgetSketchCreator : public ModuleBase_WidgetSelector
{
Q_OBJECT
- public:
+
+public:
/// Constructor
/// \param theParent the parent object
/// \param theModule a reference to a module object
/// \return the state whether the widget can accept the focus
virtual bool focusTo();
+ /// The methiod called when widget is deactivated
+ virtual void deactivate();
+
protected:
/// Saves the internal parameters to the given feature
/// \return True in success
/// The methiod called when widget is activated
virtual void activateCustom();
+ /// Visualization of the current control or others in PP
+ /// \param theSelectionControl state whether the control should be shown/hidden
+ void setVisibleSelectionControl(const bool theSelectionControl);
+
+ /// Retunrs a list of possible shape types
+ /// \return a list of shapes
+ virtual QIntList getShapeTypes() const;
+
+private:
+ /// Returns true if the selection mode is active. This is when composition feature has no
+ /// a sub-object and the attribute list is empty
+ /// \return boolean value
+ bool isSelectionMode() const;
+
private slots:
void onStarted();
void onResumed(ModuleBase_Operation* theOp);
private:
+ std::string myAttributeListID;
PartSet_Module* myModule;
/// Input control of the widget
QLineEdit* myTextLine;
+ /// List of accepting shapes types
+ QStringList myShapeTypes;
+
/// To check if we need to use body for composite feature or not
bool myUseBody;