From: vsv Date: Thu, 21 May 2015 14:25:53 +0000 (+0300) Subject: Merge branch 'Dev_1.2.0' of newgeom:newgeom into Dev_1.2.0 X-Git-Tag: V_1.2.0~123 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3574a5a3c5d5fd1105c92db5f5975ab2240344ce;hp=76ca7678fd8ced75927feff30ce02eaf8f1e62cc;p=modules%2Fshaper.git Merge branch 'Dev_1.2.0' of newgeom:newgeom into Dev_1.2.0 --- diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index d68dbe414..5783d542c 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -13,7 +13,8 @@ icon=":icons/plane.png" label="Plane face" tooltip="Select a planar face" - shape_types="face"> + shape_types="face" + default="<sketch>"> + shape_types="face" + default="<sketch>"> 1) return false; return true; } -std::string Model_AttributeSelection::namingName() +std::string Model_AttributeSelection::namingName(const std::string& theDefaultName) { std::string aName(""); - if(!this->isInitialized()) return aName; + if(!this->isInitialized()) + return !theDefaultName.empty() ? theDefaultName : aName; Handle(TDataStd_Name) anAtt; if(selectionLabel().FindAttribute(TDataStd_Name::GetID(), anAtt)) { aName = TCollection_AsciiString(anAtt->Get()).ToCString(); @@ -663,7 +664,7 @@ std::string Model_AttributeSelection::namingName() ResultPtr aCont = context(); aName = "Undefined name"; if(!aCont.get() || aCont->shape()->isNull()) - return aName; + return !theDefaultName.empty() ? theDefaultName : aName; if (!aSubSh.get() || aSubSh->isNull()) { // no subshape, so just the whole feature name return aCont->data()->name(); } diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index b900299de..19c1a1514 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -40,7 +40,8 @@ public: MODEL_EXPORT virtual bool update(); /// Returns a textual string of the selection - MODEL_EXPORT virtual std::string namingName(); + /// \param theDefaultValue a name, which is returned if the naming name can not be obtained + MODEL_EXPORT virtual std::string namingName(const std::string& theDefaultValue = ""); /// Returns an Id of the selection /// NOTE: This method has been added for temporary export of groups towards old GEOM diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index b1477e5c8..82ae16d65 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -569,8 +569,10 @@ void Model_Document::removeFeature(FeaturePtr theFeature) if (theFeature == currentFeature(false)) { int aCurrentIndex = index(theFeature); if (aCurrentIndex != -1) { - setCurrentFeature(std::dynamic_pointer_cast( - object(ModelAPI_Feature::group(), aCurrentIndex - 1)), false); + ObjectPtr aPrevObj; + if (aCurrentIndex != 0) + aPrevObj = object(ModelAPI_Feature::group(), aCurrentIndex - 1); + setCurrentFeature(std::dynamic_pointer_cast(aPrevObj), false); } } myObjs->removeFeature(theFeature); @@ -654,6 +656,7 @@ void Model_Document::setCurrentFeature(std::shared_ptr theCurr const bool theVisible) { TDF_Label aRefLab = generalLabel().FindChild(TAG_CURRENT_FEATURE); + CompositeFeaturePtr aMain; // main feature that may nest the new current if (theCurrent.get()) { /* if (theVisible) { // make features below which are not in history also enabled: sketch subs @@ -673,7 +676,8 @@ void Model_Document::setCurrentFeature(std::shared_ptr theCurr CompositeFeaturePtr aComposite = std::dynamic_pointer_cast((*aRefToMe)->owner()); if (aComposite.get() && aComposite->isSub(theCurrent)) { - theCurrent = aComposite; + aMain = aComposite; + break; } } @@ -694,10 +698,6 @@ void Model_Document::setCurrentFeature(std::shared_ptr theCurr static Events_Loop* aLoop = Events_Loop::loop(); static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); - // if the current feature is composite features, all sub-features also must be enabled - CompositeFeaturePtr aCurComp = std::dynamic_pointer_cast(theCurrent); - - bool aPassed = false; // flag that the current object is already passed in cycle FeaturePtr anIter = myObjs->lastFeature(); for(; anIter.get(); anIter = myObjs->nextFeature(anIter, true)) { @@ -705,7 +705,7 @@ void Model_Document::setCurrentFeature(std::shared_ptr theCurr if (anIter == theCurrent) aPassed = true; bool aDisabledFlag = !aPassed; - if (aCurComp.get() && aCurComp->isSub(anIter)) + if (aMain.get() && aMain->isSub(anIter)) aDisabledFlag = false; if (anIter->setDisabled(aDisabledFlag)) { // state of feature is changed => so feature become updated diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index e87508864..2356a2053 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -486,6 +486,7 @@ void Model_Objects::synchronizeFeatures( aNewFeatures.insert(aFeature); initData(aFeature, aFeatureLabel, TAG_FEATURE_ARGUMENTS); updateHistory(aFeature); + aFeature->setDisabled(false); // by default created feature is enabled (this allows to recreate the results before "setCurrent" is called) // event: model is updated ModelAPI_EventCreator::get()->sendUpdated(aFeature, aCreateEvent); @@ -600,6 +601,15 @@ void Model_Objects::synchronizeBackRefs() std::shared_ptr aRefData = std::dynamic_pointer_cast((*aRefTo)->data()); aRefData->addBackReference(aFeature, aRefsIter->first); // here the Concealed flag is updated + // update enable/disable status: the nested status must be equal to the composite + CompositeFeaturePtr aComp = + std::dynamic_pointer_cast(aFeature); + if (aComp.get()) { + FeaturePtr aReferenced = std::dynamic_pointer_cast(*aRefTo); + if (aReferenced.get()) { + aReferenced->setDisabled(aComp->isDisabled()); + } + } } } } @@ -777,7 +787,9 @@ void Model_Objects::updateResults(FeaturePtr theFeature) if (aGroup->Get() == ModelAPI_ResultBody::group().c_str()) { aNewBody = createBody(theFeature->data(), aResIndex); } else if (aGroup->Get() == ModelAPI_ResultPart::group().c_str()) { - aNewBody = createPart(theFeature->data(), aResIndex); + //aNewBody = createPart(theFeature->data(), aResIndex); + theFeature->execute(); // create the part result + break; } else if (aGroup->Get() == ModelAPI_ResultConstruction::group().c_str()) { theFeature->execute(); // construction shapes are needed for sketch solver break; diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index ea951c796..de3cddb28 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -250,6 +250,11 @@ std::list > Model_Session::allOpenedDocuments return aResult; } +bool Model_Session::isLoadByDemand(const std::string theDocID) +{ + return Model_Application::getApplication()->isLoadByDemand(theDocID); +} + std::shared_ptr Model_Session::copy( std::shared_ptr theSource, std::string theID) { diff --git a/src/Model/Model_Session.h b/src/Model/Model_Session.h index ebfef43d0..2584a2e20 100644 --- a/src/Model/Model_Session.h +++ b/src/Model/Model_Session.h @@ -90,6 +90,9 @@ class Model_Session : public ModelAPI_Session, public Events_Listener /// Returns all the opened documents of the session (without postponed) MODEL_EXPORT virtual std::list > allOpenedDocuments(); + /// Returns true if document is not loaded yet + MODEL_EXPORT virtual bool isLoadByDemand(const std::string theDocID); + /// Registers the plugin that creates features. /// It is obligatory for each plugin to call this function on loading to be found by /// the plugin manager on call of the feature) diff --git a/src/ModelAPI/ModelAPI_AttributeSelection.h b/src/ModelAPI/ModelAPI_AttributeSelection.h index 495da4180..71c850e59 100644 --- a/src/ModelAPI/ModelAPI_AttributeSelection.h +++ b/src/ModelAPI/ModelAPI_AttributeSelection.h @@ -42,7 +42,8 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute MODELAPI_EXPORT virtual std::string attributeType(); /// Returns a textual string of the selection - virtual std::string namingName() = 0; + /// \param theDefaultValue a value, which is used if the naming name can not be obtained + virtual std::string namingName(const std::string& theDefaultValue = "") = 0; /// Returns an id of the selection virtual int Id() = 0; diff --git a/src/ModelAPI/ModelAPI_Session.h b/src/ModelAPI/ModelAPI_Session.h index 5c927e7d3..47f607181 100644 --- a/src/ModelAPI/ModelAPI_Session.h +++ b/src/ModelAPI/ModelAPI_Session.h @@ -93,6 +93,9 @@ class MODELAPI_EXPORT ModelAPI_Session /// Returns all the opened documents of the session (without postponed) virtual std::list > allOpenedDocuments() = 0; + /// Returns true if document is not loaded yet + virtual bool isLoadByDemand(const std::string theDocID) = 0; + /// Copies the document to the new one with the given id virtual std::shared_ptr copy(std::shared_ptr theSource, std::string theID) = 0; diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index cea370ba2..785e98b41 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -263,7 +263,7 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName() bool isNameUpdated = false; AttributeSelectionPtr aSelect = aData->selection(attributeID()); if (aSelect) { - myTextLine->setText(QString::fromStdString(aSelect->namingName())); + myTextLine->setText(QString::fromStdString(aSelect->namingName(getDefaultValue()))); isNameUpdated = true; } if (!isNameUpdated) { @@ -283,7 +283,7 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName() } } else { - myTextLine->setText(""); + myTextLine->setText(getDefaultValue().c_str()); } } } diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index e21d756fd..2dcd3662d 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -122,10 +122,6 @@ Q_OBJECT /// \param theShape a shape virtual bool acceptSubShape(std::shared_ptr theShape) const; - // Get the shape from the attribute it the attribute contain a shape, e.g. selection attribute - /// \return a shape - GeomShapePtr getShape() const; - /// Clear attribute void clearAttribute(); @@ -136,6 +132,10 @@ Q_OBJECT /// \return true if it is succeed virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape); + /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute + /// \return a shape + virtual GeomShapePtr getShape() const; + /// Return the attribute values wrapped in a list of viewer presentations /// \return a list of viewer presentations, which contains an attribute result and /// a shape. If the attribute do not uses the shape, it is empty diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index cea864a6a..a4dbf44f6 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -21,6 +21,13 @@ #include +#include +#include +#include +#include +#include +#include + PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, @@ -63,6 +70,67 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape); } +//******************************************************************** +GeomShapePtr PartSet_WidgetShapeSelector::getShape() const +{ + // an empty shape by default + GeomShapePtr aShape; + + // 1. find an attribute value in attribute reference attribute value + DataPtr aData = myFeature->data(); + AttributePtr aAttr = aData->attribute(attributeID()); + AttributeRefAttrPtr aRefAttr = + std::dynamic_pointer_cast(aAttr); + if (aRefAttr) { + if (!aRefAttr->isObject()) { + AttributePtr anAttribute = aRefAttr->attr(); + if (anAttribute.get()) { + XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + + // 2. find visualized vertices of the attribute and if the attribute of the vertex is + // the same, return it + FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(anAttribute->owner()); + // 2.1 get visualized results of the feature + const std::list& aResList = anAttributeFeature->results(); + std::list::const_iterator anIt = aResList.begin(), aLast = aResList.end(); + for (; anIt != aLast; anIt++) { + AISObjectPtr aAISObj = aDisplayer->getAISObject(*anIt); + if (aAISObj.get() != NULL) { + Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl(); + // 2.2 find selected owners of a visualizedd object + SelectMgr_IndexedMapOfOwner aSelectedOwners; + aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners); + for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) { + Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i); + if (!anOwner.IsNull()) { + Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner); + if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) { + const TopoDS_Shape& aBRepShape = aBRepOwner->Shape(); + if (aBRepShape.ShapeType() == TopAbs_VERTEX) { + // 2.3 if the owner is vertex and an attribute of the vertex is equal to the initial + // attribute, returns the shape + AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(anAttributeFeature, + aBRepShape, sketch()); + if (aPntAttr.get() != NULL && aPntAttr == anAttribute) { + aShape = std::shared_ptr(new GeomAPI_Shape); + aShape->setImpl(new TopoDS_Shape(aBRepShape)); + break; + } + } + } + } + } + } + } + } + } + } + if (!aShape.get()) + aShape = ModuleBase_WidgetShapeSelector::getShape(); + return aShape; +} + //******************************************************************** void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid) { diff --git a/src/PartSet/PartSet_WidgetShapeSelector.h b/src/PartSet/PartSet_WidgetShapeSelector.h index f300db7e8..050b64e27 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.h +++ b/src/PartSet/PartSet_WidgetShapeSelector.h @@ -49,6 +49,13 @@ protected: /// \param theShape a selected shape, which is used in the selection attribute virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape); + /// Get the shape from the attribute if the attribute contain a shape + /// It processes the ref attr type of attributes. It obtains the referenced attribute, + /// results of the attribute feature. And it founds a vertes in the owners of the results + /// If the vertex is found, it creates a geom shape on it. + /// \return a shape + virtual GeomShapePtr getShape() const; + /// Creates a backup of the current values of the attribute /// It should be realized in the specific widget because of different /// parameters of the current attribute diff --git a/src/PartSetPlugin/PartSetPlugin_Part.cpp b/src/PartSetPlugin/PartSetPlugin_Part.cpp index 95fa5f06b..09a768acf 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Part.cpp @@ -27,7 +27,11 @@ void PartSetPlugin_Part::execute() if (!aResult) { aResult = document()->createPart(data()); setResult(aResult); - aResult->activate(); + // do not activate part by simple execution if it is not loaded yet: it must be explicitly + // activated for this + if (!ModelAPI_Session::get()->isLoadByDemand(aResult->data()->name())) { + aResult->activate(); + } } } diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 5254c1ea6..83fa8010d 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -426,19 +426,16 @@ void XGUI_Displayer::setSelected(const QList& theValues, aContext->ClearSelected(); //if (aSelected.size() > 0) { foreach (ModuleBase_ViewerPrs aPrs, theValues) { - // if (isValidSelection(aPrs)) { - //foreach(ObjectPtr aResult, theResults) { - ObjectPtr anObject = aPrs.object(); - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - if (aResult.get() && isVisible(aResult)) { - AISObjectPtr anObj = myResult2AISObjectMap[aResult]; - Handle(AIS_InteractiveObject) anAIS = anObj->impl(); - if (!anAIS.IsNull()) { - const TopoDS_Shape& aShape = aPrs.shape(); - if (!aShape.IsNull()) { - aContext->AddOrRemoveSelected(aShape, false); - } - else { + const TopoDS_Shape& aShape = aPrs.shape(); + if (!aShape.IsNull()) { + aContext->AddOrRemoveSelected(aShape, false); + } else { + ObjectPtr anObject = aPrs.object(); + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + if (aResult.get() && isVisible(aResult)) { + AISObjectPtr anObj = myResult2AISObjectMap[aResult]; + Handle(AIS_InteractiveObject) anAIS = anObj->impl(); + if (!anAIS.IsNull()) { // The methods are replaced in order to provide multi-selection, e.g. restore selection // by activating multi selector widget. It also gives an advantage that the multi // selection in OB gives multi-selection in the viewer @@ -452,7 +449,6 @@ void XGUI_Displayer::setSelected(const QList& theValues, } else { aContext->UnhilightCurrents(); aContext->ClearCurrents(); - //foreach(ObjectPtr aResult, theResults) { foreach (ModuleBase_ViewerPrs aPrs, theValues) { ObjectPtr anObject = aPrs.object(); ResultPtr aResult = std::dynamic_pointer_cast(anObject);