void FeaturesPlugin_Group::initAttributes()
{
data()->addAttribute(FeaturesPlugin_Group::NAME_ID(), ModelAPI_AttributeString::type());
- data()->addAttribute(FeaturesPlugin_Group::TYPE_ID(), ModelAPI_AttributeInteger::type());
data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeString::type());
}
void FeaturesPlugin_Group::execute()
{
- AttributeIntegerPtr aTypeAttr = boost::dynamic_pointer_cast<ModelAPI_AttributeInteger>(
- data()->attribute(FeaturesPlugin_Group::TYPE_ID()));
- if (!aTypeAttr)
+ AttributeStringPtr aNameAttr = boost::dynamic_pointer_cast<ModelAPI_AttributeString>(
+ data()->attribute(FeaturesPlugin_Group::NAME_ID()));
+ if (!aNameAttr)
return;
- int aType = aTypeAttr->value();
+ std::string aName = aNameAttr->value();
+ data()->setName(aName);
}
static const std::string MY_GROUP_ID("Group");
return MY_GROUP_ID;
}
- /// attribute name of group type
+ /// attribute name of group name
inline static const std::string& NAME_ID()
{
static const std::string MY_GROUP_NAME_ID("group_name");
return MY_GROUP_NAME_ID;
}
- /// attribute name of group type
- inline static const std::string& TYPE_ID()
- {
- static const std::string MY_GROUP_TYPE_ID("group_type");
- return MY_GROUP_TYPE_ID;
- }
/// attribute name of selected entities list
inline static const std::string& LIST_ID()
{
<stringvalue
id="group_name"
label="Name"
- tooltip="Name of the group"
- string_list="Vertices Edges Faces Solids" />
- <choice
- id="group_type"
- label="Type"
- tooltip="Type of geometry entities"
- string_list="Vertices Edges Faces Solids" />
+ tooltip="Name of the group" />
<multi_selector id="group_list"
- label="Selected objects:"
- tooltip="List of selected objects" />
+ tooltip="List of selected objects"
+ type_choice="Vertices Edges Faces Solids" />
</source>
\ No newline at end of file
{
if(!theLayout)
return;
- theLayout->setContentsMargins(5, 5, 5, 5);
- theLayout->setSpacing(5);
+ theLayout->setContentsMargins(2, 5, 5, 2);
+ theLayout->setSpacing(4);
}
void zeroMargins(QWidget* theWidget)
QWidget* ModuleBase_WidgetFactory::multiSelectorControl(QWidget* theParent)
{
ModuleBase_WidgetMultiSelector* aMultiselectorWgt =
- new ModuleBase_WidgetMultiSelector(theParent, myWidgetApi,myParentId);
+ new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi,myParentId);
myModelWidgets.append(aMultiselectorWgt);
return aMultiselectorWgt->getControl();
}
*/
#include <ModuleBase_WidgetMultiSelector.h>
+#include <ModuleBase_WidgetShapeSelector.h>
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_Tools.h>
#include <ModelAPI_AttributeString.h>
#include <Config_WidgetAPI.h>
-#include <QVBoxLayout>
+#include <QGridLayout>
#include <QLabel>
#include <QTextEdit>
#include <QObject>
#include <QString>
+#include <QComboBox>
+#include <QEvent>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <string>
ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
- const Config_WidgetAPI* theData,
- const std::string& theParentId)
- : ModuleBase_ModelWidget(theParent, theData, theParentId)
+ ModuleBase_IWorkshop* theWorkshop,
+ const Config_WidgetAPI* theData,
+ const std::string& theParentId)
+ : ModuleBase_ModelWidget(theParent, theData, theParentId),
+ myWorkshop(theWorkshop), myIsActive(false), myUseSubShapes(false)
{
myMainWidget = new QWidget(theParent);
- QVBoxLayout* aMainLay = new QVBoxLayout(myMainWidget);
+ QGridLayout* aMainLay = new QGridLayout(myMainWidget);
ModuleBase_Tools::adjustMargins(aMainLay);
- QString aTitle = QString::fromStdString(theData->widgetLabel());
- QLabel* aTitleLabel = new QLabel(aTitle, myMainWidget);
- aMainLay->addWidget(aTitleLabel);
+ QLabel* aTypeLabel = new QLabel(tr("Type"), myMainWidget);
+ aMainLay->addWidget(aTypeLabel, 0, 0);
+ myTypeCombo = new QComboBox(myMainWidget);
+ std::string aTypes = theData->getProperty("type_choice");
+ myShapeTypes = QString::fromStdString(aTypes).split(' ');
+ myTypeCombo->addItems(myShapeTypes);
+ aMainLay->addWidget(myTypeCombo, 0, 1);
+ QLabel* aListLabel = new QLabel(tr("Selected objects:"), myMainWidget);
+ aMainLay->addWidget(aListLabel, 1, 0, 1, -1);
myListControl = new QTextEdit(myMainWidget);
myListControl->setReadOnly(true);
- aMainLay->addWidget(myListControl);
- myListControl->setMinimumHeight(20);
+ aMainLay->addWidget(myListControl, 2, 0, 2, -1);
+ aMainLay->setColumnStretch(1, 1);
myMainWidget->setLayout(aMainLay);
- connect(myListControl, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged()));
+ //TODO: Move into the base class
+ myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false);
+ //TODO_END
+ connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectionTypeChanged()));
+ activateSelection(true);
}
ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector()
{
+ activateSelection(false);
}
bool ModuleBase_WidgetMultiSelector::storeValue() const
bool ModuleBase_WidgetMultiSelector::restoreValue()
{
+ return false;
// A rare case when plugin was not loaded.
if(!myFeature)
return false;
QList<QWidget*> ModuleBase_WidgetMultiSelector::getControls() const
{
QList<QWidget*> result;
+ result << myTypeCombo;
result << myListControl;
return result;
}
+
+//********************************************************************
+bool ModuleBase_WidgetMultiSelector::eventFilter(QObject* theObj, QEvent* theEvent)
+{
+ if (theObj == myListControl) {
+ if (theEvent->type() == QEvent::FocusIn)
+ activateSelection(true);
+ }
+ return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
+}
+
+void ModuleBase_WidgetMultiSelector::onSelectionChanged()
+{
+ ModuleBase_ISelection* aSelection = myWorkshop->selection();
+ NCollection_List<TopoDS_Shape> aSelectedShapes, aFilteredShapes;
+ aSelection->selectedShapes(aSelectedShapes);
+ QString aText;
+ if (!aSelectedShapes.IsEmpty()) {
+ filterShapes(aSelectedShapes, aFilteredShapes);
+ aText = QString("Items selected: %1").arg(aFilteredShapes.Size());
+ }
+ myListControl->setText(aText);
+}
+
+void ModuleBase_WidgetMultiSelector::filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
+ NCollection_List<TopoDS_Shape>& theResult)
+{
+ if(myTypeCombo->count() == 0 || theShapesToFilter.IsEmpty())
+ return;
+ TopAbs_ShapeEnum aReferenceType =
+ ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText());
+ NCollection_List<TopoDS_Shape>::Iterator anIter(theShapesToFilter);
+ for (; anIter.More(); anIter.Next()) {
+ TopoDS_Shape aShape = anIter.Value();
+ if (aShape.IsNull() || aShape.ShapeType() != aReferenceType)
+ continue;
+ theResult.Append(aShape);
+ }
+}
+
+void ModuleBase_WidgetMultiSelector::activateSelection(bool toActivate)
+{
+ myIsActive = toActivate;
+ if (myIsActive) {
+ connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ onSelectionTypeChanged();
+ } else {
+ disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ myWorkshop->deactivateSubShapesSelection();
+ }
+}
+
+void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
+{
+ QString aNewType = myTypeCombo->currentText();
+ QIntList aList;
+ aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType));
+ myWorkshop->activateSubShapesSelection(aList);
+}
#include <ModuleBase.h>
#include <ModuleBase_ModelWidget.h>
+#include <NCollection_List.hxx>
+#include <TopoDS_Shape.hxx>
+
#include <QList>
#include <QString>
#include <QStringList>
class QWidget;
class QTextEdit;
+class QComboBox;
+class ModuleBase_IWorkshop;
class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_ModelWidget
{
Q_OBJECT
public:
ModuleBase_WidgetMultiSelector(QWidget* theParent,
- const Config_WidgetAPI* theData,
- const std::string& theParentId);
+ ModuleBase_IWorkshop* theWorkshop,
+ const Config_WidgetAPI* theData,
+ const std::string& theParentId);
virtual ~ModuleBase_WidgetMultiSelector();
/// Saves the internal parameters to the given feature
/// \return a control list
virtual QList<QWidget*> getControls() const;
- //public slots:
+ virtual bool eventFilter(QObject* theObj, QEvent* theEvent);
+
+ public slots:
+ void activateSelection(bool toActivate);
+ void onSelectionTypeChanged();
+ void onSelectionChanged();
+
+ protected:
+ void filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
+ NCollection_List<TopoDS_Shape>& theResult);
private:
QTextEdit* myListControl;
+ QComboBox* myTypeCombo;
QWidget* myMainWidget;
+
+ //TODO: Move into the base of selectors
+ ModuleBase_IWorkshop* myWorkshop;
+
+ /// If true then local selector has to be activated in context
+ QStringList myShapeTypes;
+ bool myUseSubShapes;
+ bool myIsActive;
};
#endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
// Created: 2 June 2014
// Author: Vitaly Smetannikov
-#include "ModuleBase_WidgetShapeSelector.h"
-#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_WidgetShapeSelector.h>
+#include <ModuleBase_Definitions.h>
#include <ModuleBase_ISelection.h>
-#include "ModuleBase_WidgetValue.h"
+#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_Tools.h>
-#include "ModuleBase_WidgetValueFeature.h"
-
+#include <ModuleBase_WidgetValueFeature.h>
+#include <Config_WidgetAPI.h>
#include <Events_Loop.h>
-#include <ModelAPI_Events.h>
-#include <ModelAPI_Tools.h>
-
+#include <Events_Message.h>
+#include <GeomAPI_Interface.h>
+#include <GeomAPI_Shape.h>
+#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
-#include <ModelAPI_Object.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Tools.h>
#include <Config_WidgetAPI.h>
+#include <Events_Error.h>
#include <GeomAPI_Shape.h>
#include <QEvent>
#include <QDockWidget>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS_Shape.hxx>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+
+#include <list>
#include <stdexcept>
+#include <xstring>
typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
static ShapeTypes MyShapeTypes;
{
if (MyShapeTypes.count() == 0) {
MyShapeTypes["face"] = TopAbs_FACE;
+ MyShapeTypes["faces"] = TopAbs_FACE;
MyShapeTypes["vertex"] = TopAbs_VERTEX;
+ MyShapeTypes["vertices"] = TopAbs_VERTEX;
MyShapeTypes["wire"] = TopAbs_WIRE;
MyShapeTypes["edge"] = TopAbs_EDGE;
+ MyShapeTypes["edges"] = TopAbs_EDGE;
MyShapeTypes["shell"] = TopAbs_SHELL;
MyShapeTypes["solid"] = TopAbs_SOLID;
+ MyShapeTypes["solids"] = TopAbs_SOLID;
}
QString aType = theType.toLower();
if (MyShapeTypes.contains(aType))
return MyShapeTypes[aType];
- throw std::invalid_argument("Shape type defined in XML is not implemented!");
+ Events_Error::send("Shape type defined in XML is not implemented!");
+ return TopAbs_SHAPE;
}
ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent,