From: vsv Date: Mon, 22 Dec 2014 14:58:50 +0000 (+0300) Subject: Adapt shape selector to working in local context X-Git-Tag: V_0.7.0_rc1~56^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=28fbbe71be08bf61b869c6651f46bb920b75fd4c;p=modules%2Fshaper.git Adapt shape selector to working in local context --- diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 1ef62f92a..73f1f9057 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -92,7 +92,7 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen const Config_WidgetAPI* theData, const std::string& theParentId) : ModuleBase_ModelWidget(theParent, theData, theParentId), - myWorkshop(theWorkshop), myIsActive(false), myUseSubShapes(false) + myWorkshop(theWorkshop), myIsActive(false) { myContainer = new QWidget(theParent); QHBoxLayout* aLayout = new QHBoxLayout(myContainer); @@ -120,7 +120,7 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen std::string aObjTypes = theData->getProperty("object_types"); myObjectTypes = QString(aObjTypes.c_str()).split(' ', QString::SkipEmptyParts); - myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false); + //myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false); } //******************************************************************** @@ -137,45 +137,30 @@ bool ModuleBase_WidgetShapeSelector::storeValue() const return false; DataPtr aData = myFeature->data(); - if (myUseSubShapes) { - ResultPtr aBody = std::dynamic_pointer_cast(mySelectedObject); - if (aBody) { - AttributePtr aAttr = aData->attribute(attributeID()); - - // We have to check several attributes types - AttributeSelectionPtr aSelectAttr = - std::dynamic_pointer_cast(aAttr); - if (aSelectAttr) { - aSelectAttr->setValue(aBody, myShape); - updateObject(myFeature); - return true; - } else { - AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - if (aRefAttr) { - aRefAttr->setObject(mySelectedObject); - updateObject(myFeature); - return true; - } - } + AttributeReferencePtr aRef = aData->reference(attributeID()); + if (aRef) { + ObjectPtr aObject = aRef->value(); + if (!(aObject && aObject->isSame(mySelectedObject))) { + aRef->setValue(mySelectedObject); + updateObject(myFeature); + return true; } } else { - AttributeReferencePtr aRef = aData->reference(attributeID()); - if (aRef) { - ObjectPtr aObject = aRef->value(); + AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); + if (aRefAttr) { + ObjectPtr aObject = aRefAttr->object(); if (!(aObject && aObject->isSame(mySelectedObject))) { - aRef->setValue(mySelectedObject); + aRefAttr->setObject(mySelectedObject); updateObject(myFeature); return true; } } else { - AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - if (aRefAttr) { - ObjectPtr aObject = aRefAttr->object(); - if (!(aObject && aObject->isSame(mySelectedObject))) { - aRefAttr->setObject(mySelectedObject); - updateObject(myFeature); - return true; - } + AttributeSelectionPtr aSelectAttr = aData->selection(attributeID()); + ResultPtr aBody = std::dynamic_pointer_cast(mySelectedObject); + if (aSelectAttr && aBody && (myShape.get() != NULL)) { + aSelectAttr->setValue(aBody, myShape); + updateObject(myFeature); + return true; } } } @@ -207,26 +192,21 @@ bool ModuleBase_WidgetShapeSelector::restoreValue() { DataPtr aData = myFeature->data(); bool isBlocked = this->blockSignals(true); - if (myUseSubShapes) { - AttributeSelectionPtr aSelect = aData->selection(attributeID()); - if (aSelect) { - mySelectedObject = aSelect->context(); - myShape = aSelect->value(); + + AttributeSelectionPtr aSelect = aData->selection(attributeID()); + if (aSelect) { + mySelectedObject = aSelect->context(); + myShape = aSelect->value(); + } else { + AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); + if (aRefAttr) { + mySelectedObject = aRefAttr->object(); } else { - AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - if (aRefAttr) { - mySelectedObject = aRefAttr->object(); + AttributeReferencePtr aRef = aData->reference(attributeID()); + if (aRef) { + mySelectedObject = aRef->value(); } } - } else { - AttributeReferencePtr aRef = aData->reference(attributeID()); - if (aRef) - mySelectedObject = aRef->value(); - else { - AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - if (aRefAttr) - mySelectedObject = aRefAttr->object(); - } } updateSelectionName(); @@ -293,21 +273,17 @@ bool ModuleBase_WidgetShapeSelector::setSelection(ModuleBase_ViewerPrs theValue) return false; // Get sub-shapes from local selection - if (myUseSubShapes) { - if (!theValue.shape().IsNull()) { - aShape = std::shared_ptr(new GeomAPI_Shape()); - aShape->setImpl(new TopoDS_Shape(theValue.shape())); - } + if (!theValue.shape().IsNull()) { + aShape = std::shared_ptr(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(theValue.shape())); } // Check that the selection corresponds to selection type - if (myUseSubShapes) { - if (!acceptSubShape(aShape)) - return false; - } else { - if (!acceptObjectShape(aObject)) - return false; - } + if (!acceptSubShape(aShape)) + return false; +// if (!acceptObjectShape(aObject)) +// return false; + if (isValid(aObject, aShape)) { setObject(aObject, aShape); return true; @@ -328,33 +304,34 @@ void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, std::shared_ptr } //******************************************************************** -bool ModuleBase_WidgetShapeSelector::acceptObjectShape(const ObjectPtr theResult) const -{ - ResultPtr aResult = std::dynamic_pointer_cast(theResult); - - // Check that the shape of necessary type - std::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); - if (!aShapePtr) - return false; - TopoDS_Shape aShape = aShapePtr->impl(); - 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; -} +//bool ModuleBase_WidgetShapeSelector::acceptObjectShape(const ObjectPtr theResult) const +//{ +// ResultPtr aResult = std::dynamic_pointer_cast(theResult); +// +// // Check that the shape of necessary type +// std::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); +// if (!aShapePtr) +// return false; +// TopoDS_Shape aShape = aShapePtr->impl(); +// 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; +//} //******************************************************************** bool ModuleBase_WidgetShapeSelector::acceptSubShape(std::shared_ptr theShape) const @@ -412,27 +389,23 @@ void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate) if (myIsActive) { connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - if (myUseSubShapes) { - - QIntList aList; - foreach (QString aType, myShapeTypes) - aList.append(shapeType(aType)); - myWorkshop->activateSubShapesSelection(aList); - if (!myObjectTypes.isEmpty()) { - myObjTypeFilter = new ModuleBase_ObjectTypesFilter(myWorkshop, myObjectTypes); - aViewer->clearSelectionFilters(); - aViewer->addSelectionFilter(myObjTypeFilter); - } + QIntList aList; + foreach (QString aType, myShapeTypes) { + aList.append(shapeType(aType)); + } + myWorkshop->activateSubShapesSelection(aList); + if (!myObjectTypes.isEmpty()) { + myObjTypeFilter = new ModuleBase_ObjectTypesFilter(myWorkshop, myObjectTypes); + aViewer->clearSelectionFilters(); + aViewer->addSelectionFilter(myObjTypeFilter); } } else { disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - if (myUseSubShapes) { - if (!myObjTypeFilter.IsNull()) { - aViewer->removeSelectionFilter(myObjTypeFilter); - myObjTypeFilter.Nullify(); - } - myWorkshop->deactivateSubShapesSelection(); + if (!myObjTypeFilter.IsNull()) { + aViewer->removeSelectionFilter(myObjTypeFilter); + myObjTypeFilter.Nullify(); } + myWorkshop->deactivateSubShapesSelection(); } // apply filters loaded from the XML definition of the widget ModuleBase_FilterFactory* aFactory = myWorkshop->selectionFilters(); diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index a64932a24..7757d3141 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -84,7 +84,7 @@ Q_OBJECT /// Returns true if shape of given object corresponds to requested shape type /// This method is called only in non sub-shapes selection mode - virtual bool acceptObjectShape(const ObjectPtr theObject) const; + //virtual bool acceptObjectShape(const ObjectPtr theObject) const; /// Returns true if selected shape corresponds to requested shape types /// This method is called only in sub-shapes selection mode @@ -118,9 +118,6 @@ Q_OBJECT QStringList myShapeTypes; QStringList myObjectTypes; - /// If true then local selector has to be activated in context - bool myUseSubShapes; - bool myIsActive; Handle(ModuleBase_ObjectTypesFilter) myObjTypeFilter; diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index 04f026112..bd9a98be5 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -33,7 +33,7 @@ bool PartSet_WidgetShapeSelector::storeValue() const } else { // Processing of sketch object DataPtr aData = myFeature->data(); - if (myUseSubShapes && myShape) { + if (myShape) { AttributePtr aAttr = aData->attribute(attributeID()); AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(aAttr); diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index 970cb045c..c53bc38f4 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -72,6 +72,9 @@ void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes) void XGUI_ModuleConnector::deactivateSubShapesSelection() { XGUI_Displayer* aDisp = myWorkshop->displayer(); + // Clear selection modes + QIntList aModes; + aDisp->activateObjects(aModes); // The document limitation selection has to be only during operation //aDisp->removeSelectionFilter(myDocumentShapeFilter); //aDisp->closeLocalContexts(false);