X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetShapeSelector.cpp;h=86f7a3471d935804915ccdb23045586cee2abd45;hb=28c90c232ffe159b88edd156286a398bfa3bb73b;hp=f07c339caa60e82bd6a68645d904559758b1d4d3;hpb=6d36d303911b5f436d2f2a9fe94f2976509df029;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index f07c339ca..86f7a3471 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -6,8 +6,10 @@ #include #include #include +#include #include #include + #include #include #include @@ -19,10 +21,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -46,8 +50,7 @@ #include #include -#include -#include +#include typedef QMap ShapeTypes; static ShapeTypes MyShapeTypes; @@ -106,7 +109,10 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen aLayout->addWidget(myTextLine, 1); std::string aTypes = theData->getProperty("shape_types"); - myShapeTypes = QString(aTypes.c_str()).split(' '); + myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts); + + std::string aObjTypes = theData->getProperty("object_types"); + myObjectTypes = QString(aObjTypes.c_str()).split(' ', QString::SkipEmptyParts); myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false); } @@ -129,9 +135,12 @@ bool ModuleBase_WidgetShapeSelector::storeValue() const boost::shared_ptr aSelect = boost::dynamic_pointer_cast(aData->attribute(attributeID())); - ResultBodyPtr aBody = boost::dynamic_pointer_cast(mySelectedObject); - if (aBody) + ResultPtr aBody = boost::dynamic_pointer_cast(mySelectedObject); + if (aBody) { aSelect->setValue(aBody, myShape); + updateObject(myFeature); + return true; + } } else { boost::shared_ptr aRef = boost::dynamic_pointer_cast(aData->attribute(attributeID())); @@ -140,9 +149,10 @@ bool ModuleBase_WidgetShapeSelector::storeValue() const if (!(aObject && aObject->isSame(mySelectedObject))) { aRef->setValue(mySelectedObject); updateObject(myFeature); + return true; } } - return true; + return false; } //******************************************************************** @@ -183,14 +193,41 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged() ObjectPtr aObject = aObjects.first(); if ((!mySelectedObject) && (!aObject)) return; - if (mySelectedObject && aObject && mySelectedObject->isSame(aObject)) + + // Check that the selected object is result (others can not be accepted) + ResultPtr aRes = boost::dynamic_pointer_cast(aObject); + if (!aRes) + return; + + if (myFeature) { + // We can not select a result of our feature + const std::list>& aResList = myFeature->results(); + std::list >::const_iterator aIt; + for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) { + if ((*aIt) == aRes) + return; + } + } + // 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; + + // Check that the result has a shape + GeomShapePtr aShape = ModelAPI_Tools::shape(aRes); + if (!aShape) + return; + + /// Check that object has acceptable type + if (!acceptObjectType(aObject)) return; // Get sub-shapes from local selection - boost::shared_ptr aShape; if (myUseSubShapes) { NCollection_List aShapeList; - myWorkshop->selection()->selectedShapes(aShapeList); + std::list aOwners; + myWorkshop->selection()->selectedShapes(aShapeList, aOwners); if (aShapeList.Extent() > 0) { aShape = boost::shared_ptr(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(aShapeList.First())); @@ -199,13 +236,14 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged() // Check that the selection corresponds to selection type if (myUseSubShapes) { - if (!isAccepted(aShape)) + if (!acceptSubShape(aShape)) return; } else { - if (!isAccepted(aObject)) + if (!acceptObjectShape(aObject)) return; } setObject(aObject, aShape); + //activateSelection(false); emit focusOutWidget(this); } } @@ -213,8 +251,6 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged() //******************************************************************** void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, boost::shared_ptr theShape) { - if (mySelectedObject == theObj) - return; mySelectedObject = theObj; myShape = theShape; if (mySelectedObject) { @@ -222,7 +258,6 @@ void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, boost::shared_p if (!myUseSubShapes) { static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE); ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent); - Events_Loop::loop()->flush(anEvent); } } updateSelectionName(); @@ -231,23 +266,9 @@ void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, boost::shared_p } //******************************************************************** -bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const +bool ModuleBase_WidgetShapeSelector::acceptObjectShape(const ObjectPtr theResult) const { ResultPtr aResult = boost::dynamic_pointer_cast(theResult); - if (myFeature) { - // We can not select a result of our feature - const std::list>& aRes = myFeature->results(); - std::list >::const_iterator aIt; - for (aIt = aRes.cbegin(); aIt != aRes.cend(); ++aIt) { - if ((*aIt) == aResult) - return false; - } - } - // Check that object belongs to active document or PartSet - DocumentPtr aDoc = aResult->document(); - SessionPtr aMgr = ModelAPI_Session::get(); - if (!(aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument())) - return false; // Check that the shape of necessary type boost::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); @@ -274,7 +295,7 @@ bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const } //******************************************************************** -bool ModuleBase_WidgetShapeSelector::isAccepted(boost::shared_ptr theShape) const +bool ModuleBase_WidgetShapeSelector::acceptSubShape(boost::shared_ptr theShape) const { TopoDS_Shape aShape = theShape->impl(); foreach (QString aType, myShapeTypes) { @@ -284,6 +305,26 @@ bool ModuleBase_WidgetShapeSelector::isAccepted(boost::shared_ptr return false; } +//******************************************************************** +bool ModuleBase_WidgetShapeSelector::acceptObjectType(const ObjectPtr theObject) const +{ + // Definition of types is not obligatory. If types are not defined then + // it means that accepted any type + if (myObjectTypes.isEmpty()) + return true; + + foreach (QString aType, myObjectTypes) { + if (aType.toLower() == "construction") { + ResultConstructionPtr aConstr = + boost::dynamic_pointer_cast(theObject); + return (aConstr != NULL); + } // ToDo: Process other types of objects + } + // Object type is defined but not found + return false; +} + + //******************************************************************** void ModuleBase_WidgetShapeSelector::updateSelectionName() { @@ -320,15 +361,26 @@ 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); + myWorkshop->viewer()->clearSelectionFilters(); + myWorkshop->viewer()->addSelectionFilter(myObjTypeFilter); + } } } else { disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - if (myUseSubShapes) + if (myUseSubShapes) { + if (!myObjTypeFilter.IsNull()) { + myWorkshop->viewer()->removeSelectionFilter(myObjTypeFilter); + myObjTypeFilter.Nullify(); + } myWorkshop->deactivateSubShapesSelection(); + } } } @@ -374,7 +426,7 @@ bool ModuleBase_WidgetShapeSelector::setValue(ModuleBase_WidgetValue* theValue) dynamic_cast(theValue); if (aFeatureValue && aFeatureValue->object()) { ObjectPtr aObject = aFeatureValue->object(); - if (isAccepted(aObject)) { + if (acceptObjectShape(aObject)) { setObject(aObject); return true; }