-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate)
-{
- updateSelectionName();
-
- if (toActivate) {
- QIntList aList;
- foreach (QString aType, myShapeTypes) {
- aList.append(ModuleBase_Tools::shapeType(aType));
- }
- myWorkshop->activateSubShapesSelection(aList);
- } else {
- myWorkshop->deactivateSubShapesSelection();
- }
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::raisePanel() const
-{
- QWidget* aParent = this->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();
- }
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::activateCustom()
-{
- connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
- activateSelection(true);
-
- // Restore selection in the viewer by the attribute selection list
- myWorkshop->setSelected(getAttributeSelection());
-
- activateFilters(myWorkshop, true);
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::storeAttributeValue()
-{
- DataPtr aData = myFeature->data();
- AttributePtr anAttribute = myFeature->attribute(attributeID());
-
- myObject = GeomValidators_Tools::getObject(anAttribute);
- myShape = getShape();
- myRefAttribute = AttributePtr();
- myIsObject = false;
- AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
- if (aRefAttr) {
- myIsObject = aRefAttr->isObject();
- myRefAttribute = aRefAttr->attr();
- }
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid)
-{
- DataPtr aData = myFeature->data();
- AttributePtr anAttribute = myFeature->attribute(attributeID());
-
- setObject(myObject, myShape);
- AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
- if (aRefAttr) {
- if (!myIsObject)
- aRefAttr->setAttr(myRefAttribute);
- }
-}
-
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::customValidators(
- std::list<ModelAPI_Validator*>& theValidators,
- std::list<std::list<std::string> >& theArguments) const
-{
- return;
- theValidators.push_back(myShapeValidator);
-
- std::list<std::string> anArguments;
- foreach(QString aType, myShapeTypes) {
- anArguments.push_back(aType.toStdString().c_str());
- }
- theArguments.push_back(anArguments);
-}
-
-//********************************************************************
-bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
-{
- bool isDone = false;
-
- // It should be checked by corresponded validator
- ObjectPtr aObject = thePrs.object();
- ObjectPtr aCurrentObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID()));
- /*
- if ((!aCurrentObject) && (!aObject))
- return false;*/
-
- // It should be checked by corresponded validator
- // Check that the selected object is result (others can not be accepted)
- ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
- if (!aRes)
- return false;
- /*if (myFeature) {
- // We can not select a result of our feature
- const std::list<std::shared_ptr<ModelAPI_Result>>& aResList = myFeature->results();
- std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
- for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
- if ((*aIt) == aRes)
- return false;
- }
- }
- */
- // It should be checked by corresponded validator
- /*
- // Check that object belongs to active document or PartSet
- DocumentPtr aDoc = aRes->document();
- SessionPtr aMgr = ModelAPI_Session::get();
- if (!(aDoc == aMgr->activeDocument()) && !(aDoc == aMgr->moduleDocument()))
- return false;*/
-
- // It should be checked by corresponded validator
- // Check that the result has a shape
- GeomShapePtr aShape = ModelAPI_Tools::shape(aRes);
- if (!aShape)
- return false;
-
- // Get sub-shapes from local selection
- if (!thePrs.shape().IsNull()) {
- aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
- aShape->setImpl(new TopoDS_Shape(thePrs.shape()));
- }
- // Check that the selection corresponds to selection type
- TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
- if (!acceptSubShape(aTopoShape))
- return false;
-
- setObject(aObject, aShape);
- return true;
-}
-