X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetShapeSelector.cpp;h=bd5e54e707b51b445aeeaad5f50eb4cac305047b;hb=dcd54507eb794c21a02c95ad26c1779c36481274;hp=3fb534b36482d1effb4df9ee153ffc0c085e1218;hpb=6ff1eb27b19a3f97d844994727d184576d4ab32e;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 3fb534b36..bd5e54e70 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -2,23 +2,30 @@ // Created: 2 June 2014 // Author: Vitaly Smetannikov -#include "ModuleBase_WidgetShapeSelector.h" -#include +#include +#include #include -#include "ModuleBase_WidgetValue.h" +#include #include -#include "ModuleBase_WidgetValueFeature.h" - +#include +#include #include -#include -#include - +#include +#include +#include +#include #include #include -#include +#include +#include #include #include +#include +#include +#include +#include #include +#include #include @@ -34,7 +41,13 @@ #include #include -#include +#include +#include + +#include + +#include +#include typedef QMap ShapeTypes; static ShapeTypes MyShapeTypes; @@ -43,15 +56,21 @@ TopAbs_ShapeEnum ModuleBase_WidgetShapeSelector::shapeType(const QString& theTyp { 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; } - if (MyShapeTypes.contains(theType)) - return MyShapeTypes[theType]; - throw std::invalid_argument("Shape type defined in XML is not implemented!"); + QString aType = theType.toLower(); + if (MyShapeTypes.contains(aType)) + return MyShapeTypes[aType]; + Events_Error::send("Shape type defined in XML is not implemented!"); + return TopAbs_SHAPE; } ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent, @@ -59,7 +78,7 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen const Config_WidgetAPI* theData, const std::string& theParentId) : ModuleBase_ModelWidget(theParent, theData, theParentId), - myWorkshop(theWorkshop), myIsActive(false) + myWorkshop(theWorkshop), myIsActive(false), myUseSubShapes(false) { myContainer = new QWidget(theParent); QHBoxLayout* aLayout = new QHBoxLayout(myContainer); @@ -88,11 +107,14 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen std::string aTypes = theData->getProperty("shape_types"); myShapeTypes = QString(aTypes.c_str()).split(' '); + + myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false); } //******************************************************************** ModuleBase_WidgetShapeSelector::~ModuleBase_WidgetShapeSelector() { + activateSelection(false); } //******************************************************************** @@ -103,25 +125,45 @@ bool ModuleBase_WidgetShapeSelector::storeValue() const return false; DataPtr aData = myFeature->data(); - boost::shared_ptr aRef = boost::dynamic_pointer_cast< - ModelAPI_AttributeReference>(aData->attribute(attributeID())); - - ObjectPtr aObject = aRef->value(); - if (!(aObject && aObject->isSame(mySelectedObject))) { - aRef->setValue(mySelectedObject); - updateObject(myFeature); + if (myUseSubShapes) { + boost::shared_ptr aSelect = + boost::dynamic_pointer_cast(aData->attribute(attributeID())); + + 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())); + + ObjectPtr aObject = aRef->value(); + if (!(aObject && aObject->isSame(mySelectedObject))) { + aRef->setValue(mySelectedObject); + updateObject(myFeature); + return true; + } } - return true; + return false; } //******************************************************************** bool ModuleBase_WidgetShapeSelector::restoreValue() { DataPtr aData = myFeature->data(); - boost::shared_ptr aRef = aData->reference(attributeID()); - bool isBlocked = this->blockSignals(true); - mySelectedObject = aRef->value(); + if (myUseSubShapes) { + boost::shared_ptr aSelect = aData->selection(attributeID()); + if (aSelect) { + mySelectedObject = aSelect->context(); + myShape = aSelect->value(); + } + } else { + boost::shared_ptr aRef = aData->reference(attributeID()); + mySelectedObject = aRef->value(); + } updateSelectionName(); this->blockSignals(isBlocked); @@ -147,27 +189,52 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged() return; if (mySelectedObject && aObject && mySelectedObject->isSame(aObject)) return; - - // Check that the selection corresponds to selection type - if (!isAccepted(aObject)) + // Check that the selected object is result (others can not be accepted) + ResultPtr aRes = boost::dynamic_pointer_cast(aObject); + if (!aRes) + return; + // Check that the result has a shape + GeomShapePtr aShape = ModelAPI_Tools::shape(aRes); + if (!aShape) return; - setObject(aObject); + // Get sub-shapes from local selection + if (myUseSubShapes) { + NCollection_List 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())); + } + } + + // Check that the selection corresponds to selection type + if (myUseSubShapes) { + if (!isAccepted(aShape)) + return; + } else { + if (!isAccepted(aObject)) + return; + } + setObject(aObject, aShape); emit focusOutWidget(this); } } //******************************************************************** -void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj) +void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, boost::shared_ptr theShape) { if (mySelectedObject == theObj) return; mySelectedObject = theObj; + myShape = theShape; if (mySelectedObject) { raisePanel(); - static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE); - ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent); - Events_Loop::loop()->flush(anEvent); + if (!myUseSubShapes) { + static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE); + ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent); + } } updateSelectionName(); activateSelection(false); @@ -217,6 +284,17 @@ bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const return false; } +//******************************************************************** +bool ModuleBase_WidgetShapeSelector::isAccepted(boost::shared_ptr theShape) const +{ + TopoDS_Shape aShape = theShape->impl(); + foreach (QString aType, myShapeTypes) { + if (aShape.ShapeType() == shapeType(aType)) + return true; + } + return false; +} + //******************************************************************** void ModuleBase_WidgetShapeSelector::updateSelectionName() { @@ -250,10 +328,19 @@ void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate) myTextLine->setPalette(myInactivePalet); updateSelectionName(); - if (myIsActive) + if (myIsActive) { connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - else + if (myUseSubShapes) { + QIntList aList; + foreach (QString aType, myShapeTypes) + aList.append(shapeType(aType)); + myWorkshop->activateSubShapesSelection(aList); + } + } else { disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); + if (myUseSubShapes) + myWorkshop->deactivateSubShapesSelection(); + } } //********************************************************************