// same document, use reference attribute
if (anObjLab.IsNull() || owner()->document() == theObject->document()) {
- std::shared_ptr<Model_Document> aDoc =
- std::dynamic_pointer_cast<Model_Document>(owner()->document());
if (anObjLab.IsNull()) {
myRef->Set(myRef->Label());
} else {
#include <ModelAPI_Feature.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultPart.h>
#include <ModelAPI_CompositeFeature.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_PlanarEdges.h>
static const int kSTART_VERTEX_DELTA = 1000000;
// identifier that there is simple reference: selection equals to context
Standard_GUID kSIMPLE_REF_ID("635eacb2-a1d6-4dec-8348-471fae17cb29");
+// simple reference in the construction
Standard_GUID kCONSTUCTION_SIMPLE_REF_ID("635eacb2-a1d6-4dec-8348-471fae17cb28");
+// reference to Part sub-object
+Standard_GUID kPART_REF_ID("635eacb2-a1d6-4dec-8348-471fae17cb27");
// on this label is stored:
// TNaming_NamedShape - selected shape
} else {
selectConstruction(theContext, theSubShape);
}
+ } else if (theContext->groupName() == ModelAPI_ResultPart::group()) {
+ aSelLab.ForgetAllAttributes(true);
+ TDataStd_UAttribute::Set(aSelLab, kPART_REF_ID);
+ selectPart(theContext, theSubShape);
}
//the attribute initialized state should be changed by sendAttributeUpdated only
//myIsInitialized = true;
registerSubShape(selectionLabel(), aSubShape, 0, aContextFeature, aMyDoc, "", aRefs);
}
+void Model_AttributeSelection::selectPart(
+ const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+ // store the shape (in case part is not loaded it should be usefull
+ TopoDS_Shape aShape;
+ std::string aName = theContext->data()->name();
+ if (theSubShape->isNull()) {// the whole part shape is selected
+ aShape = theContext->shape()->impl<TopoDS_Shape>();
+ } else {
+ aShape = theSubShape->impl<TopoDS_Shape>();
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theContext);
+ aName += "/" + aPart->nameInPart(theSubShape);
+ }
+ TNaming_Builder aBuilder(selectionLabel());
+ aBuilder.Select(aShape, aShape);
+ // identify by name in the part
+ TDataStd_Name::Set(selectionLabel(), aName.c_str());
+}
+
TDF_Label Model_AttributeSelection::selectionLabel()
{
return myRef.myRef->Label().FindChild(1);
virtual void selectConstruction(
const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
+ /// Performs the selection for the part result (selection by name of body result inside of part)
+ virtual void selectPart(
+ const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
+
/// Returns the label where TNaming_Selection results are stored
/// Note: there must be no attributes stored at the same label because Selector clears this lab
TDF_Label selectionLabel();
bool Model_Data::isDisplayed()
{
- return myObject.get() && myObject->document().get() && myObject->document()->isActive() &&
+ return myObject.get() && myObject->document().get() &&
+ (myObject->document()->isActive() ||
+ myObject->document() == ModelAPI_Session::get()->moduleDocument()) && // root is accessible allways
myFlags->Value(kFlagDisplayed) == Standard_True;
}
friend class Model_AttributeReference;
friend class Model_AttributeRefAttr;
friend class Model_AttributeRefList;
+ friend class Model_ResultPart;
friend class DFBrowser;
private:
{
createHistory(theGroupID);
//TODO: mpv stabilization hotfix
- if (myHistory[theGroupID].size() <= theIndex)
+ if (myHistory[theGroupID].size() <= (const unsigned int)theIndex)
return ObjectPtr();
return myHistory[theGroupID][theIndex];
}
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);
- theFeature->execute(); // create the part result
+ std::shared_ptr<ModelAPI_ResultPart> aNewP = createPart(theFeature->data(), aResIndex);
+ theFeature->setResult(aNewP, aResIndex);
+ if (!aNewP->partDoc().get())
+ theFeature->execute(); // create the part result: it is better to restore the previous result if it is possible
break;
} else if (aGroup->Get() == ModelAPI_ResultConstruction::group().c_str()) {
theFeature->execute(); // construction shapes are needed for sketch solver
if (ModelAPI_ResultPart::setDisabled(theThis, theFlag)) {
DocumentPtr aDoc = Model_ResultPart::partDoc();
if (aDoc.get()) {
+ // make the current feature the last in any case: to update shapes defore deactivation too
+ FeaturePtr aLastFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aDoc->object(
+ ModelAPI_Feature::group(), aDoc->size(ModelAPI_Feature::group()) - 1));
+ aDoc->setCurrentFeature(aLastFeature, false);
if (theFlag) { // disable, so make all features disabled too
+ // update the shape just before the deactivation: it will be used outside of part
+ myShape.Nullify();
+ shape();
aDoc->setCurrentFeature(FeaturePtr(), false);
- } else { // enabled, so make the current feature the last inside of this document
- FeaturePtr aLastFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aDoc->object(
- ModelAPI_Feature::group(), aDoc->size(ModelAPI_Feature::group()) - 1));
- aDoc->setCurrentFeature(aLastFeature, false);
}
}
return true;
std::shared_ptr<GeomAPI_Shape> Model_ResultPart::shape()
{
- DocumentPtr aDoc = Model_ResultPart::partDoc();
- if (aDoc.get()) {
- const std::string& aBodyGroup = ModelAPI_ResultBody::group();
- TopoDS_Compound aResultComp;
- BRep_Builder aBuilder;
- aBuilder.MakeCompound(aResultComp);
- int aNumSubs = 0;
- for(int a = aDoc->size(aBodyGroup) - 1; a >= 0; a--) {
- ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(aDoc->object(aBodyGroup, a));
- if (aBody.get() && aBody->shape().get()) {
- TopoDS_Shape aShape = *(aBody->shape()->implPtr<TopoDS_Shape>());
- if (!aShape.IsNull()) {
- aBuilder.Add(aResultComp, aShape);
- aNumSubs++;
+ if (myShape.IsNull()) {
+ DocumentPtr aDoc = Model_ResultPart::partDoc();
+ if (aDoc.get()) {
+ const std::string& aBodyGroup = ModelAPI_ResultBody::group();
+ TopoDS_Compound aResultComp;
+ BRep_Builder aBuilder;
+ aBuilder.MakeCompound(aResultComp);
+ int aNumSubs = 0;
+ for(int a = aDoc->size(aBodyGroup) - 1; a >= 0; a--) {
+ ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(aDoc->object(aBodyGroup, a));
+ if (aBody.get() && aBody->shape().get() && !aBody->isDisabled()) {
+ TopoDS_Shape aShape = *(aBody->shape()->implPtr<TopoDS_Shape>());
+ if (!aShape.IsNull()) {
+ aBuilder.Add(aResultComp, aShape);
+ aNumSubs++;
+ }
}
}
+ if (aNumSubs) {
+ myShape = aResultComp;
+ }
}
- if (aNumSubs) {
- std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
- aResult->setImpl(new TopoDS_Shape(aResultComp));
- return aResult;
+ }
+ if (myShape.IsNull())
+ return std::shared_ptr<GeomAPI_Shape>();
+ std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
+ aResult->setImpl(new TopoDS_Shape(myShape));
+ return aResult;
+}
+
+#include <Model_Document.h>
+#include <TNaming_Tool.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TNaming_Iterator.hxx>
+#include <TDataStd_Name.hxx>
+
+std::string Model_ResultPart::nameInPart(const std::shared_ptr<GeomAPI_Shape>& theShape)
+{
+ TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+ // getting an access to the document of part
+ std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(partDoc());
+ if (!aDoc.get()) // the part document is not presented for the moment
+ return "";
+ TDF_Label anAccessLabel = aDoc->generalLabel();
+
+ std::string aName;
+ // check if the subShape is already in DF
+ Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aShape, anAccessLabel);
+ Handle(TDataStd_Name) anAttr;
+ if(!aNS.IsNull() && !aNS->IsEmpty()) { // in the document
+ if(aNS->Label().FindAttribute(TDataStd_Name::GetID(), anAttr)) {
+ aName = TCollection_AsciiString(anAttr->Get()).ToCString();
+ if(!aName.empty()) {
+ const TDF_Label& aLabel = aDoc->findNamingName(aName);
+
+ static const std::string aPostFix("_");
+ TNaming_Iterator anItL(aNS);
+ for(int i = 1; anItL.More(); anItL.Next(), i++) {
+ if(anItL.NewShape() == aShape) {
+ aName += aPostFix;
+ aName += TCollection_AsciiString (i).ToCString();
+ break;
+ }
+ }
+ }
}
}
+ return aName;
+}
+
+std::shared_ptr<GeomAPI_Shape> Model_ResultPart::shapeInPart(const std::string& theName)
+{
+ /// TODO: not implemented yet
return std::shared_ptr<GeomAPI_Shape>();
}
#include "Model.h"
#include <ModelAPI_ResultPart.h>
+#include <TopoDS_Shape.hxx>
/**\class Model_ResultPart
* \ingroup DataModel
*/
class Model_ResultPart : public ModelAPI_ResultPart
{
+ TopoDS_Shape myShape; ///< shape of this part created from bodies (updated only of Part deactivation)
public:
/// Returns the part-document of this result
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> partDoc();
/// Result shape of part document is compound of bodies inside of this part
MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shape();
+ /// Returns the name of the shape inside of the part
+ MODEL_EXPORT virtual std::string nameInPart(const std::shared_ptr<GeomAPI_Shape>& theShape);
+ /// Returns the shape by the name in the part
+ MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shapeInPart(const std::string& theName);
+
/// Returns the parameters of color definition in the resources config manager
MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
std::string& theDefault);
/// Returns true if document is activated (loaded into the memory)
virtual bool isActivated() = 0;
+
+ /// Returns the name of the shape inside of the part
+ virtual std::string nameInPart(const std::shared_ptr<GeomAPI_Shape>& theShape) = 0;
+ /// Returns the shape by the name in the part
+ virtual std::shared_ptr<GeomAPI_Shape> shapeInPart(const std::string& theName) = 0;
};
//! Pointer on feature object