label="Select a face"
icon=":icons/sketch.png"
tooltip="Select a face for extrusion"
- activate="true"
+ activate="true"
+ shape_types="face"
/>
<doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set size of extrusion"/>
<boolvalue id="extrusion_reverse" label="Reverse" default="false" tooltip="Reverse default direction"/>
ModuleBase_WidgetFactory.h
ModuleBase_WidgetPoint2D.h
ModuleBase_WidgetSwitch.h
- ModuleBase_SelectorWidget.h
+ ModuleBase_WidgetSelector.h
ModuleBase_IWorkshop.h
)
ModuleBase_WidgetFactory.cpp
ModuleBase_WidgetPoint2D.cpp
ModuleBase_WidgetSwitch.cpp
- ModuleBase_SelectorWidget.cpp
+ ModuleBase_WidgetSelector.cpp
)
SET(PROJECT_LIBRARIES
${CMAKE_SOURCE_DIR}/src/Model
${CMAKE_SOURCE_DIR}/src/ModelAPI
${CMAKE_SOURCE_DIR}/src/GeomDataAPI
+ ${CMAKE_SOURCE_DIR}/src/GeomAPI
)
ADD_DEFINITIONS(-DMODULEBASE_EXPORTS ${CAS_DEFINITIONS})
+++ /dev/null
-// File: ModuleBase_SelectorWidget.h
-// Created: 2 June 2014
-// Author: Vitaly Smetannikov
-
-
-#include "ModuleBase_SelectorWidget.h"
-#include "ModuleBase_IWorkshop.h"
-
-#include <Events_Loop.h>
-#include <Model_Events.h>
-
-#include <ModelAPI_Data.h>
-#include <ModelAPI_Object.h>
-#include <ModelAPI_AttributeReference.h>
-#include <Config_WidgetAPI.h>
-
-#include <QWidget>
-#include <QLayout>
-#include <QLabel>
-#include <QLineEdit>
-#include <QToolButton>
-#include <QString>
-#include <QEvent>
-#include <QDockWidget>
-
-
-ModuleBase_SelectorWidget::ModuleBase_SelectorWidget(QWidget* theParent,
- ModuleBase_IWorkshop* theWorkshop,
- const Config_WidgetAPI* theData)
-: ModuleBase_ModelWidget(theParent, theData), myWorkshop(theWorkshop), myActivateOnStart(false)
-{
- myContainer = new QWidget(theParent);
- QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
-
- aLayout->setContentsMargins(0, 0, 0, 0);
- QString aLabelText = QString::fromStdString(theData->widgetLabel());
- QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
- myLabel = new QLabel(aLabelText, myContainer);
- myLabel->setPixmap(QPixmap(aLabelIcon));
-
- aLayout->addWidget(myLabel);
-
- QString aToolTip = QString::fromStdString(theData->widgetTooltip());
- myTextLine = new QLineEdit(myContainer);
- myTextLine->setReadOnly(true);
- myTextLine->setToolTip(aToolTip);
- myTextLine->installEventFilter(this);
-
- aLayout->addWidget(myTextLine);
-
- myActivateBtn = new QToolButton(myContainer);
- myActivateBtn->setIcon(QIcon(":icons/hand_point.png"));
- myActivateBtn->setCheckable(true);
- myActivateBtn->setToolTip(tr("Activate/Deactivate selection"));
- connect(myActivateBtn, SIGNAL(toggled(bool)), this, SLOT(activateSelection(bool)));
-
- aLayout->addWidget(myActivateBtn);
-
- QString aActivateTxt = QString::fromStdString(theData->getProperty("activate"));
- if (!aActivateTxt.isNull()) {
- myActivateOnStart = (aActivateTxt == "true");
- }
-}
-
-//********************************************************************
-ModuleBase_SelectorWidget::~ModuleBase_SelectorWidget()
-{
-}
-
-//********************************************************************
-bool ModuleBase_SelectorWidget::storeValue(FeaturePtr theFeature) const
-{
- DataPtr aData = theFeature->data();
- boost::shared_ptr<ModelAPI_AttributeReference> aRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(attributeID()));
-
- FeaturePtr aFeature = aRef->value();
- if (!(aFeature && aFeature->isSame(mySelectedFeature))) {
- aRef->setValue(mySelectedFeature);
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
- }
- return true;
-}
-
-//********************************************************************
-bool ModuleBase_SelectorWidget::restoreValue(FeaturePtr theFeature)
-{
- DataPtr aData = theFeature->data();
- boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
-
- bool isBlocked = this->blockSignals(true);
- mySelectedFeature = aRef->value();
- updateSelectionName();
-
- this->blockSignals(isBlocked);
- return true;
-}
-
-//********************************************************************
-QList<QWidget*> ModuleBase_SelectorWidget::getControls() const
-{
- QList<QWidget*> aControls;
- aControls.append(myLabel);
- aControls.append(myTextLine);
- aControls.append(myActivateBtn);
- return aControls;
-}
-
-//********************************************************************
-void ModuleBase_SelectorWidget::onSelectionChanged()
-{
- QList<FeaturePtr> aFeatures = myWorkshop->selectedFeatures();
- if (aFeatures.size() > 0) {
- FeaturePtr aFeature = aFeatures.first();
- if ((!mySelectedFeature) && (!aFeature))
- return;
- if (mySelectedFeature && aFeature && mySelectedFeature->isSame(aFeature))
- return;
-
- // TODO: Check that the selection corresponds to selection type
- // TODO: Use the feature kind definition like SKETCH_KIND instead of the direct text
- if (aFeature->getKind().compare("Sketch") != 0)
- return;
-
- mySelectedFeature = aFeature;
- if (mySelectedFeature) {
- updateSelectionName();
- activateSelection(false);
- raisePanel();
- } else {
- myTextLine->setText("");
- }
- emit valuesChanged();
- }
-}
-
-//********************************************************************
-void ModuleBase_SelectorWidget::updateSelectionName()
-{
- if (mySelectedFeature) {
- std::string aName;
- if (mySelectedFeature->data())
- aName = mySelectedFeature->data()->getName();
- else
- aName = boost::dynamic_pointer_cast<ModelAPI_Object>(mySelectedFeature)->getName();
-
- myTextLine->setText(QString::fromStdString(aName));
- } else
- myTextLine->setText("");
-}
-
-//********************************************************************
-bool ModuleBase_SelectorWidget::eventFilter(QObject* theObj, QEvent* theEvent)
-{
- if (theObj == myTextLine) {
- if (theEvent->type() == QEvent::Polish) {
- activateSelection(myActivateOnStart);
- onSelectionChanged();
- }
- }
- return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
-}
-
-//********************************************************************
-void ModuleBase_SelectorWidget::enableOthersControls(bool toEnable) const
-{
- QWidget* aParent = myContainer->parentWidget();
- QList<QWidget*> aChldList = aParent->findChildren<QWidget*>();
- foreach(QWidget* aWgt, aChldList) {
- if ((aWgt != myLabel) && (aWgt != myActivateBtn) && (aWgt != myTextLine) && (aWgt != myContainer))
- aWgt->setEnabled(toEnable);
- }
-}
-
-//********************************************************************
-void ModuleBase_SelectorWidget::activateSelection(bool toActivate)
-{
- enableOthersControls(!toActivate);
- myTextLine->setEnabled(toActivate);
-
- if (toActivate)
- connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
- else
- disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
-
- myActivateBtn->setDown(toActivate);
-}
-
-//********************************************************************
-void ModuleBase_SelectorWidget::raisePanel() const
-{
- QWidget* aParent = myContainer->parentWidget();
- QWidget* aLastPanel = 0;
- while (!aParent->inherits("QDockWidget")) {
- aLastPanel = aParent;
- aParent = aParent->parentWidget();
- if (!aParent) return;
- }
- if (aParent->inherits("QDockWidget")) {
- QDockWidget* aTabWgt = (QDockWidget*) aParent;
- aTabWgt->raise();
- }
-}
\ No newline at end of file
+++ /dev/null
-// File: ModuleBase_SelectorWidget.h
-// Created: 2 June 2014
-// Author: Vitaly Smetannikov
-
-#ifndef ModuleBase_SelectorWidget_H
-#define ModuleBase_SelectorWidget_H
-
-#include "ModuleBase.h"
-#include "ModuleBase_ModelWidget.h"
-
-#include <ModelAPI_Feature.h>
-
-
-class Config_WidgetAPI;
-class QWidget;
-class QLabel;
-class QLineEdit;
-class QToolButton;
-class ModuleBase_IWorkshop;
-
-class MODULEBASE_EXPORT ModuleBase_SelectorWidget: public ModuleBase_ModelWidget
-{
- Q_OBJECT
-public:
- ModuleBase_SelectorWidget(QWidget* theParent,
- ModuleBase_IWorkshop* theWorkshop,
- const Config_WidgetAPI* theData);
-
- virtual ~ModuleBase_SelectorWidget();
-
- /// Saves the internal parameters to the given feature
- /// \param theFeature a model feature to be changed
- virtual bool storeValue(FeaturePtr theFeature) const;
-
- virtual bool restoreValue(FeaturePtr theFeature);
-
- /// Returns the internal parent wiget control, that can be shown anywhere
- /// \returns the widget
- QWidget* getControl() const { return myContainer; }
-
- /// Returns list of widget controls
- /// \return a control list
- virtual QList<QWidget*> getControls() const;
-
- void setActivationOnStart(bool toActivate) { myActivateOnStart = toActivate; }
- bool activateOnStart() const { return myActivateOnStart; }
-
- FeaturePtr selectedFeature() const { return mySelectedFeature; }
-
-public slots:
-
- /// Activate or deactivate selection
- void activateSelection(bool toActivate);
-
-protected:
- bool eventFilter(QObject* theObj, QEvent* theEvent);
-
-private slots:
- void onSelectionChanged();
-
-private:
- void enableOthersControls(bool toEnable) const;
- void updateSelectionName();
- void raisePanel() const;
-
- QWidget* myContainer;
- QLabel* myLabel;
- QLineEdit* myTextLine;
- QToolButton* myActivateBtn;
-
- ModuleBase_IWorkshop* myWorkshop;
-
- bool myActivateOnStart;
-
- FeaturePtr mySelectedFeature;
-};
-
-#endif
\ No newline at end of file
#include <ModuleBase_OperationDescription.h>
#include <ModuleBase_WidgetPoint2D.h>
#include <ModuleBase_WidgetSwitch.h>
-#include <ModuleBase_SelectorWidget.h>
+#include <ModuleBase_WidgetSelector.h>
#include <ModuleBase_WidgetDoubleValue.h>
#include <ModuleBase_WidgetBoolValue.h>
QWidget* ModuleBase_WidgetFactory::selectorControl(QWidget* theParent)
{
- ModuleBase_SelectorWidget* aSelector = new ModuleBase_SelectorWidget(theParent, myWorkshop, myWidgetApi);
+ ModuleBase_WidgetSelector* aSelector = new ModuleBase_WidgetSelector(theParent, myWorkshop, myWidgetApi);
QObject::connect(aSelector, SIGNAL(valuesChanged()), myOperation, SLOT(storeCustomValue()));
--- /dev/null
+// File: ModuleBase_WidgetSelector.h
+// Created: 2 June 2014
+// Author: Vitaly Smetannikov
+
+
+#include "ModuleBase_WidgetSelector.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <Events_Loop.h>
+#include <Model_Events.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeReference.h>
+#include <Config_WidgetAPI.h>
+
+#include <GeomAPI_Shape.h>
+
+#include <TopoDS_Shape.hxx>
+#include <TopExp_Explorer.hxx>
+
+#include <QWidget>
+#include <QLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QToolButton>
+#include <QString>
+#include <QEvent>
+#include <QDockWidget>
+
+
+typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
+static ShapeTypes MyShapeTypes;
+
+TopAbs_ShapeEnum ModuleBase_WidgetSelector::shapeType(const QString& theType)
+{
+ if (MyShapeTypes.count() == 0) {
+ MyShapeTypes["face"] = TopAbs_FACE;
+ MyShapeTypes["vertex"] = TopAbs_VERTEX;
+ MyShapeTypes["wire"] = TopAbs_WIRE;
+ MyShapeTypes["edge"] = TopAbs_EDGE;
+ MyShapeTypes["shell"] = TopAbs_SHELL;
+ MyShapeTypes["solid"] = TopAbs_SOLID;
+ }
+ if (MyShapeTypes.contains(theType))
+ return MyShapeTypes[theType];
+ throw std::invalid_argument("Shape type defined in XML is not implemented!");
+}
+
+
+
+
+ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent,
+ ModuleBase_IWorkshop* theWorkshop,
+ const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData), myWorkshop(theWorkshop), myActivateOnStart(false)
+{
+ myContainer = new QWidget(theParent);
+ QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
+
+ aLayout->setContentsMargins(0, 0, 0, 0);
+ QString aLabelText = QString::fromStdString(theData->widgetLabel());
+ QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+ myLabel = new QLabel(aLabelText, myContainer);
+ myLabel->setPixmap(QPixmap(aLabelIcon));
+
+ aLayout->addWidget(myLabel);
+
+ QString aToolTip = QString::fromStdString(theData->widgetTooltip());
+ myTextLine = new QLineEdit(myContainer);
+ myTextLine->setReadOnly(true);
+ myTextLine->setToolTip(aToolTip);
+ myTextLine->installEventFilter(this);
+
+ aLayout->addWidget(myTextLine);
+
+ myActivateBtn = new QToolButton(myContainer);
+ myActivateBtn->setIcon(QIcon(":icons/hand_point.png"));
+ myActivateBtn->setCheckable(true);
+ myActivateBtn->setToolTip(tr("Activate/Deactivate selection"));
+ connect(myActivateBtn, SIGNAL(toggled(bool)), this, SLOT(activateSelection(bool)));
+
+ aLayout->addWidget(myActivateBtn);
+
+ QString aActivateTxt = QString::fromStdString(theData->getProperty("activate"));
+ if (!aActivateTxt.isNull()) {
+ myActivateOnStart = (aActivateTxt == "true");
+ }
+
+ std::string aTypes = theData->getProperty("shape_types");
+ myShapeTypes = QString(aTypes.c_str()).split(',');
+}
+
+//********************************************************************
+ModuleBase_WidgetSelector::~ModuleBase_WidgetSelector()
+{
+}
+
+//********************************************************************
+bool ModuleBase_WidgetSelector::storeValue(FeaturePtr theFeature) const
+{
+ DataPtr aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeReference> aRef =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(attributeID()));
+
+ FeaturePtr aFeature = aRef->value();
+ if (!(aFeature && aFeature->isSame(mySelectedFeature))) {
+ aRef->setValue(mySelectedFeature);
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ }
+ return true;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetSelector::restoreValue(FeaturePtr theFeature)
+{
+ DataPtr aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
+
+ bool isBlocked = this->blockSignals(true);
+ mySelectedFeature = aRef->value();
+ updateSelectionName();
+
+ this->blockSignals(isBlocked);
+ return true;
+}
+
+//********************************************************************
+QList<QWidget*> ModuleBase_WidgetSelector::getControls() const
+{
+ QList<QWidget*> aControls;
+ aControls.append(myLabel);
+ aControls.append(myTextLine);
+ aControls.append(myActivateBtn);
+ return aControls;
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::onSelectionChanged()
+{
+ QList<FeaturePtr> aFeatures = myWorkshop->selectedFeatures();
+ if (aFeatures.size() > 0) {
+ FeaturePtr aFeature = aFeatures.first();
+ if ((!mySelectedFeature) && (!aFeature))
+ return;
+ if (mySelectedFeature && aFeature && mySelectedFeature->isSame(aFeature))
+ return;
+
+ // Check that the selection corresponds to selection type
+ if (!isAccepted(aFeature)) return;
+
+ mySelectedFeature = aFeature;
+ if (mySelectedFeature) {
+ updateSelectionName();
+ activateSelection(false);
+ raisePanel();
+ } else {
+ myTextLine->setText("");
+ }
+ emit valuesChanged();
+ }
+}
+
+//********************************************************************
+bool ModuleBase_WidgetSelector::isAccepted(const FeaturePtr theFeature) const
+{
+ boost::shared_ptr<GeomAPI_Shape> aShapePtr = theFeature->data()->shape();
+ if (!aShapePtr) return false;
+ TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
+ if (aShape.IsNull()) return false;
+
+ TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
+ if (aShapeType == TopAbs_COMPOUND) {
+ foreach (QString aType, myShapeTypes) {
+ TopExp_Explorer aEx(aShape, shapeType(aType));
+ if (aEx.More())
+ return true;
+ }
+ } else {
+ foreach (QString aType, myShapeTypes) {
+ if (shapeType(aType) == aShapeType)
+ return true;
+ }
+ }
+ return false;
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::updateSelectionName()
+{
+ if (mySelectedFeature) {
+ std::string aName;
+ if (mySelectedFeature->data())
+ aName = mySelectedFeature->data()->getName();
+ else
+ aName = boost::dynamic_pointer_cast<ModelAPI_Object>(mySelectedFeature)->getName();
+
+ myTextLine->setText(QString::fromStdString(aName));
+ } else
+ myTextLine->setText("");
+}
+
+//********************************************************************
+bool ModuleBase_WidgetSelector::eventFilter(QObject* theObj, QEvent* theEvent)
+{
+ if (theObj == myTextLine) {
+ if (theEvent->type() == QEvent::Polish) {
+ activateSelection(myActivateOnStart);
+ onSelectionChanged();
+ }
+ }
+ return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::enableOthersControls(bool toEnable) const
+{
+ QWidget* aParent = myContainer->parentWidget();
+ QList<QWidget*> aChldList = aParent->findChildren<QWidget*>();
+ foreach(QWidget* aWgt, aChldList) {
+ if ((aWgt != myLabel) && (aWgt != myActivateBtn) && (aWgt != myTextLine) && (aWgt != myContainer))
+ aWgt->setEnabled(toEnable);
+ }
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::activateSelection(bool toActivate)
+{
+ enableOthersControls(!toActivate);
+ myTextLine->setEnabled(toActivate);
+
+ if (toActivate)
+ connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ else
+ disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+
+ myActivateBtn->setDown(toActivate);
+}
+
+//********************************************************************
+void ModuleBase_WidgetSelector::raisePanel() const
+{
+ QWidget* aParent = myContainer->parentWidget();
+ QWidget* aLastPanel = 0;
+ while (!aParent->inherits("QDockWidget")) {
+ aLastPanel = aParent;
+ aParent = aParent->parentWidget();
+ if (!aParent) return;
+ }
+ if (aParent->inherits("QDockWidget")) {
+ QDockWidget* aTabWgt = (QDockWidget*) aParent;
+ aTabWgt->raise();
+ }
+}
\ No newline at end of file
--- /dev/null
+// File: ModuleBase_WidgetSelector.h
+// Created: 2 June 2014
+// Author: Vitaly Smetannikov
+
+#ifndef ModuleBase_WidgetSelector_H
+#define ModuleBase_WidgetSelector_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_ModelWidget.h"
+
+#include <ModelAPI_Feature.h>
+
+#include <TopAbs_ShapeEnum.hxx>
+
+#include <QStringList>
+
+
+class Config_WidgetAPI;
+class QWidget;
+class QLabel;
+class QLineEdit;
+class QToolButton;
+class ModuleBase_IWorkshop;
+
+class MODULEBASE_EXPORT ModuleBase_WidgetSelector: public ModuleBase_ModelWidget
+{
+ Q_OBJECT
+public:
+ ModuleBase_WidgetSelector(QWidget* theParent,
+ ModuleBase_IWorkshop* theWorkshop,
+ const Config_WidgetAPI* theData);
+
+ virtual ~ModuleBase_WidgetSelector();
+
+ /// Saves the internal parameters to the given feature
+ /// \param theFeature a model feature to be changed
+ virtual bool storeValue(FeaturePtr theFeature) const;
+
+ virtual bool restoreValue(FeaturePtr theFeature);
+
+ /// Returns the internal parent wiget control, that can be shown anywhere
+ /// \returns the widget
+ QWidget* getControl() const { return myContainer; }
+
+ /// Returns list of widget controls
+ /// \return a control list
+ virtual QList<QWidget*> getControls() const;
+
+ void setActivationOnStart(bool toActivate) { myActivateOnStart = toActivate; }
+ bool activateOnStart() const { return myActivateOnStart; }
+
+ FeaturePtr selectedFeature() const { return mySelectedFeature; }
+
+public slots:
+
+ /// Activate or deactivate selection
+ void activateSelection(bool toActivate);
+
+protected:
+ bool eventFilter(QObject* theObj, QEvent* theEvent);
+
+private slots:
+ void onSelectionChanged();
+
+private:
+ void enableOthersControls(bool toEnable) const;
+ void updateSelectionName();
+ void raisePanel() const;
+ bool isAccepted(const FeaturePtr theFeature) const;
+
+ static TopAbs_ShapeEnum shapeType(const QString& theType);
+
+ QWidget* myContainer;
+ QLabel* myLabel;
+ QLineEdit* myTextLine;
+ QToolButton* myActivateBtn;
+
+ ModuleBase_IWorkshop* myWorkshop;
+
+ bool myActivateOnStart;
+
+ FeaturePtr mySelectedFeature;
+ QStringList myShapeTypes;
+};
+
+#endif
\ No newline at end of file
std::set<FeaturePtr>::const_iterator aIt;
for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
FeaturePtr aFeature = (*aIt);
- if (aFeature->getKind() != PARTSET_PART_KIND)
- myDisplayer->redisplay(aFeature, false);
+ if (aFeature->getKind() != PARTSET_PART_KIND) {
+ if (myDisplayer->isVisible(aFeature))
+ myDisplayer->redisplay(aFeature, false);
+ else
+ myDisplayer->display(aFeature, false);
+ }
}
myDisplayer->updateViewer();
}