icon=":icons/plane.png"
label="Plane face"
tooltip="Select a planar face"
- shape_types="face">
+ shape_types="face"
+ default="<sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
<doublevalue
icon=":icons/plane_inverted.png"
label="Plane face"
tooltip="Select a planar face"
- shape_types="face">
+ shape_types="face"
+ default="<sketch>">
<validator id="GeomValidators_Face" parameters="plane"/>
</shape_selector>
<doublevalue
if(aNumber > 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();
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();
}
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
if (theFeature == currentFeature(false)) {
int aCurrentIndex = index(theFeature);
if (aCurrentIndex != -1) {
- setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(
- object(ModelAPI_Feature::group(), aCurrentIndex - 1)), false);
+ ObjectPtr aPrevObj;
+ if (aCurrentIndex != 0)
+ aPrevObj = object(ModelAPI_Feature::group(), aCurrentIndex - 1);
+ setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aPrevObj), false);
}
}
myObjs->removeFeature(theFeature);
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
CompositeFeaturePtr aComposite =
std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*aRefToMe)->owner());
if (aComposite.get() && aComposite->isSub(theCurrent)) {
- theCurrent = aComposite;
+ aMain = aComposite;
+ break;
}
}
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<ModelAPI_CompositeFeature>(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)) {
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
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);
std::shared_ptr<Model_Data> aRefData =
std::dynamic_pointer_cast<Model_Data>((*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<ModelAPI_CompositeFeature>(aFeature);
+ if (aComp.get()) {
+ FeaturePtr aReferenced = std::dynamic_pointer_cast<ModelAPI_Feature>(*aRefTo);
+ if (aReferenced.get()) {
+ aReferenced->setDisabled(aComp->isDisabled());
+ }
+ }
}
}
}
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;
return aResult;
}
+bool Model_Session::isLoadByDemand(const std::string theDocID)
+{
+ return Model_Application::getApplication()->isLoadByDemand(theDocID);
+}
+
std::shared_ptr<ModelAPI_Document> Model_Session::copy(
std::shared_ptr<ModelAPI_Document> theSource, std::string theID)
{
/// Returns all the opened documents of the session (without postponed)
MODEL_EXPORT virtual std::list<std::shared_ptr<ModelAPI_Document> > 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)
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;
/// Returns all the opened documents of the session (without postponed)
virtual std::list<std::shared_ptr<ModelAPI_Document> > 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<ModelAPI_Document> copy(std::shared_ptr<ModelAPI_Document> theSource,
std::string theID) = 0;
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) {
}
}
else {
- myTextLine->setText("");
+ myTextLine->setText(getDefaultValue().c_str());
}
}
}
/// \param theShape a shape
virtual bool acceptSubShape(std::shared_ptr<GeomAPI_Shape> 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();
/// \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
#include <XGUI_Workshop.h>
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_Displayer.h>
+#include <XGUI_SelectionMgr.h>
+#include <XGUI_Selection.h>
+#include <SelectMgr_IndexedMapOfOwner.hxx>
+#include <StdSelect_BRepOwner.hxx>
+
PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
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<ModelAPI_AttributeRefAttr>(aAttr);
+ if (aRefAttr) {
+ if (!aRefAttr->isObject()) {
+ AttributePtr anAttribute = aRefAttr->attr();
+ if (anAttribute.get()) {
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(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<ResultPtr>& aResList = anAttributeFeature->results();
+ std::list<ResultPtr>::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<Handle(AIS_InteractiveObject)>();
+ // 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<GeomAPI_Shape>(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)
{
/// \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
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();
+ }
}
}
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<ModelAPI_Result>(anObject);
- if (aResult.get() && isVisible(aResult)) {
- AISObjectPtr anObj = myResult2AISObjectMap[aResult];
- Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
- 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<ModelAPI_Result>(anObject);
+ if (aResult.get() && isVisible(aResult)) {
+ AISObjectPtr anObj = myResult2AISObjectMap[aResult];
+ Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
+ 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
} else {
aContext->UnhilightCurrents();
aContext->ClearCurrents();
- //foreach(ObjectPtr aResult, theResults) {
foreach (ModuleBase_ViewerPrs aPrs, theValues) {
ObjectPtr anObject = aPrs.object();
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);