# aGroupFeature.data().setName("")
# aSelectionListAttr = aGroupFeature.selectionList("group_list")
# aSelectionListAttr.setSelectionType("face")
-# aSelectionListAttr.append("Box_1_1/Shape1_1")
-# aSelectionListAttr.append("Box_1_1/Shape2_1")
+# aSelectionListAttr.append("Box_1_1/Shape1")
+# aSelectionListAttr.append("Box_1_1/Shape2")
# aGroupFeature.execute()
aSession.finishOperation()
aSelectionList = aFeature1.selectionList("group_list")
assert aSelectionList.selectionType() == "solid"
assert aSelectionList.size() == 1
- assert aSelectionList.value(0).namingName("") == "mygeom_1_1"
+ assert aSelectionList.value(0).namingName("") == "mygeom_1"
aFeature2 = aCompositeFeature.subFeature(1, False)
assert aFeature2.getKind() == "Group"
aSelectionList = aFeature2.selectionList("group_list")
assert aSelectionList.selectionType() == "face"
assert aSelectionList.size() == 2
- assert aSelectionList.value(0).namingName("") == "mygeom_1/Shape1_1"
- assert aSelectionList.value(1).namingName("") == "mygeom_1/Shape2_1"
+ assert aSelectionList.value(0).namingName("") == "mygeom_1/Shape1"
+ print aSelectionList.value(1).namingName("")
+ assert aSelectionList.value(1).namingName("") == "mygeom_1/Shape2"
if __name__ == '__main__':
#=========================================================================
}
}
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-
// the viewer update should be unblocked in order to avoid the features blinking before they are
// hidden
aMsg = std::shared_ptr<Events_Message>(
new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
Events_Loop::loop()->send(aMsg);
-
- } else if (theMessage.get()) {
- Events_InfoMessage("InitializationPlugin_Plugin",
- "InitializationPlugin_Plugin::processEvent: unhandled message caught: %1")
- .arg(theMessage->eventID().eventText()).send();
}
}
//myIsInitialized = true;
owner()->data()->sendAttributeUpdated(this);
-
- std::string aSelName = namingName();
- if(!aSelName.empty())
- TDataStd_Name::Set(selectionLabel(), aSelName.c_str()); //set name
}
std::shared_ptr<GeomAPI_Shape> Model_AttributeSelection::value()
std::string 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();
- return aName;
- }
std::shared_ptr<GeomAPI_Shape> aSubSh = value();
ResultPtr aCont = context();
TDataStd_Name::Set(aSubBuilder.NamedShape()->Label(), aSolidName.c_str());
}
}
+ } else if(!aBuilder.NamedShape()->IsEmpty()) {
+ Handle(TDataStd_Name) anAttr;
+ if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
+ std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString());
+ if(!aName.empty()) {
+ std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
+ aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
+ }
+ }
}
}
}
void Model_BodyBuilder::buildName(const int theTag, const std::string& theName)
{
- std::string aName = data()->name() + "/" + theName;
std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(document());
- aDoc->addNamingName(builder(theTag)->NamedShape()->Label(), aName);
- TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(),aName.c_str());
+ //aDoc->addNamingName(builder(theTag)->NamedShape()->Label(), theName);
+ TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(), theName.c_str());
}
void Model_BodyBuilder::generated(
const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag)
TDF_Label aChildLabel = aLabel.FindChild(aTag);
TNaming_Builder aBuilder(aChildLabel);
aBuilder.Generated(anOldShape, anExp.Current());
- TCollection_AsciiString aChildName = TCollection_AsciiString((data()->name() + "/" + theName + "_").c_str()) + aTag;
- aDoc->addNamingName(aChildLabel, aChildName.ToCString());
+ TCollection_AsciiString aChildName = TCollection_AsciiString((theName + "_").c_str()) + aTag;
+ //aDoc->addNamingName(aChildLabel, aChildName.ToCString());
TDataStd_Name::Set(aChildLabel, aChildName.ToCString());
aTag++;
}
TDF_Label aChildLabel = aLabel.FindChild(aTag);
TNaming_Builder aBuilder(aChildLabel);
aBuilder.Generated(aRoot, anExp.Current());
- TCollection_AsciiString aChildName = TCollection_AsciiString((data()->name() + "/" + theName + "_").c_str()) + aTag;
- aDoc->addNamingName(aChildLabel, aChildName.ToCString());
+ TCollection_AsciiString aChildName = TCollection_AsciiString((theName + "_").c_str()) + aTag;
+ //aDoc->addNamingName(aChildLabel, aChildName.ToCString());
TDataStd_Name::Set(aChildLabel, aChildName.ToCString());
aTag++;
}
}
}
- /* TopTools_IndexedDataMapOfShapeListOfShape aDM;
- TopExp::MapShapesAndAncestors(aShape, TopAbs_EDGE, TopAbs_FACE, aDM);
- for(int i=1; i <= aDM.Extent(); i++) {
- if(aDM.FindFromIndex(i).Extent() > 1) continue;
- if (BRep_Tool::Degenerated(TopoDS::Edge(aDM.FindKey(i))))
- continue;
- builder(theTag)->Generated(aDM.FindKey(i));
- TCollection_AsciiString aStr(theTag);
- std::string aName = theName + aStr.ToCString();
- buildName(theTag, aName);
- #ifdef DEB_IMPORT
- aName += + ".brep";
- BRepTools::Write(aDM.FindKey(i), aName.c_str());
- #endif
- theTag++;
- }
- */
TopTools_MapOfShape anEdgesToDelete;
TopExp_Explorer anEx(aShape,TopAbs_EDGE);
std::string aName;
}
if (mySendAttributeUpdated && isModified)
ModelAPI_ObjectRenamedMessage::send(myObject, anOldName, theName, this);
+ if (isModified && myObject && myObject->document()) {
+ std::dynamic_pointer_cast<Model_Document>(myObject->document())->
+ changeNamingName(anOldName, theName);
+ }
}
AttributePtr Model_Data::addAttribute(const std::string& theID, const std::string theAttrType)
myNamingNames[theName] = theLabel;
}
+void Model_Document::changeNamingName(const std::string theOldName, const std::string theNewName)
+{
+ std::map<std::string, TDF_Label>::iterator aFind = myNamingNames.find(theOldName);
+ if (aFind != myNamingNames.end()) {
+ myNamingNames[theNewName] = aFind->second;
+ myNamingNames.erase(theOldName);
+ }
+}
+
TDF_Label Model_Document::findNamingName(std::string theName)
{
std::map<std::string, TDF_Label>::iterator aFind = myNamingNames.find(theName);
- if (aFind == myNamingNames.end())
- return TDF_Label(); // not found
- return aFind->second;
+ if (aFind != myNamingNames.end()) {
+ return aFind->second;
+ }
+ // not found exact name, try to find by sub-components
+ std::string::size_type aSlash = theName.rfind('/');
+ if (aSlash != std::string::npos) {
+ std::string anObjName = theName.substr(0, aSlash);
+ aFind = myNamingNames.find(anObjName);
+ if (aFind != myNamingNames.end()) {
+ TCollection_ExtendedString aSubName(theName.substr(aSlash + 1).c_str());
+ // searching sub-labels with this name
+ TDF_ChildIDIterator aNamesIter(aFind->second, TDataStd_Name::GetID(), Standard_True);
+ for(; aNamesIter.More(); aNamesIter.Next()) {
+ Handle(TDataStd_Name) aName = Handle(TDataStd_Name)::DownCast(aNamesIter.Value());
+ if (aName->Get() == aSubName)
+ return aName->Label();
+ }
+ }
+ }
+ return TDF_Label(); // not found
}
ResultPtr Model_Document::findByName(const std::string theName)
//! Registers the name of the shape for the topological naming needs
void addNamingName(const TDF_Label theLabel, std::string theName);
+ //! Updates the name of some object
+ void changeNamingName(std::string theOldName, const std::string theNewName);
//! Returns the label, keeper of the name for the topological naming needs
TDF_Label findNamingName(std::string theName);
//! Returns the result by name of the result (names of results must be unique, used for naming
friend class Model_AttributeSelection;
friend class Model_ResultPart;
friend class Model_ResultCompSolid;
+ friend class Model_SelectionNaming;
friend class DFBrowser;
private:
friend class Model_AttributeReference;
friend class Model_AttributeRefAttr;
friend class Model_AttributeRefList;
+ friend class Model_AttributeRefList;
+ friend class Model_SelectionNaming;
};
#endif
#include "Model_SelectionNaming.h"
#include "Model_Document.h"
+#include "Model_Objects.h"
#include <ModelAPI_Feature.h>
#include <Events_InfoMessage.h>
#include <ModelAPI_Session.h>
}
std::string Model_SelectionNaming::getShapeName(
- std::shared_ptr<Model_Document> theDoc, const TopoDS_Shape& theShape)
+ std::shared_ptr<Model_Document> theDoc, const TopoDS_Shape& theShape,
+ const bool theAddContextName)
{
std::string aName;
// check if the subShape is already in DF
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 = theDoc->findNamingName(aName);
+ // indexes are added to sub-shapes not primitives (primitives must not be located at the same label)
+ if(!aName.empty() && aNS->Evolution() != TNaming_PRIMITIVE && theAddContextName) {
+ const TDF_Label& aLabel = aNS->Label();//theDoc->findNamingName(aName);
static const std::string aPostFix("_");
TNaming_Iterator anItL(aNS);
for(int i = 1; anItL.More(); anItL.Next(), i++) {
break;
}
}
- }
+ }
+ if (theAddContextName && aName.find("/") == std::string::npos) { // searching for the context object
+ for(TDF_Label anObjL = aNS->Label(); anObjL.Depth() > 4; anObjL = anObjL.Father()) {
+ int aDepth = anObjL.Depth();
+ if (aDepth == 5 || aDepth == 7) {
+ ObjectPtr anObj = theDoc->objects()->object(anObjL);
+ if (anObj) {
+ aName = anObj->data()->name() + "/" + aName;
+ }
+ }
+ }
+ }
}
}
return aName;
#endif
std::shared_ptr<Model_Document> aDoc =
std::dynamic_pointer_cast<Model_Document>(theContext->document());
+ if (theContext->groupName() == ModelAPI_ResultPart::group()) {
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theContext);
+ int anIndex;
+ return aPart->data()->name() + "/" + aPart->nameInPart(theSubSh, anIndex);
+ }
+
+ // add the result name to the name of the shape (it was in BodyBuilder, but did not work on Result rename)
+ bool isNeedContextName = theContext->shape().get() && !theContext->shape()->isEqual(theSubSh);
// check if the subShape is already in DF
- aName = getShapeName(aDoc, aSubShape);
+ aName = getShapeName(aDoc, aSubShape, isNeedContextName);
if(aName.empty() ) { // not in the document!
TopAbs_ShapeEnum aType = aSubShape.ShapeType();
switch (aType) {
// build name of the sub-shape Edge
for(int i=1; i <= aSMap.Extent(); i++) {
const TopoDS_Shape& aFace = aSMap.FindKey(i);
- std::string aFaceName = getShapeName(aDoc, aFace);
+ std::string aFaceName = getShapeName(aDoc, aFace, isNeedContextName);
if(i == 1)
aName = aFaceName;
else
}
TopTools_ListIteratorOfListOfShape itl(aListOfNbs);
for (;itl.More();itl.Next()) {
- std::string aFaceName = getShapeName(aDoc, itl.Value());
+ std::string aFaceName = getShapeName(aDoc, itl.Value(), isNeedContextName);
aName += "&" + aFaceName;
}
}
TopTools_ListIteratorOfListOfShape itl(aListE);
for (int i = 1;itl.More();itl.Next(),i++) {
const TopoDS_Shape& anEdge = itl.Value();
- std::string anEdgeName = getShapeName(aDoc, anEdge);
+ std::string anEdgeName = getShapeName(aDoc, anEdge, isNeedContextName);
if (anEdgeName.empty()) { // edge is not in DS, trying by faces anyway
isByFaces = true;
aName.clear();
TopTools_ListIteratorOfListOfShape itl(aList);
for (int i = 1;itl.More();itl.Next(),i++) {
const TopoDS_Shape& aFace = itl.Value();
- std::string aFaceName = getShapeName(aDoc, aFace);
+ std::string aFaceName = getShapeName(aDoc, aFace, isNeedContextName);
if(i == 1)
aName = aFaceName;
else
}
break;
}
- // register name
- // aDoc->addNamingName(selectionLabel(), aName);
- // the selected sub-shape will not be shared and as result it will not require registration
}
+
return aName;
}
if (n == std::string::npos) n = 0;
std::string aSubString = theSubShapeName.substr(n + 1);
n = aSubString.rfind('_');
- if (n == std::string::npos) return aSelection;
- aSubString = aSubString.substr(n+1);
- int indx = atoi(aSubString.c_str());
+ int indx;
+ if (n == std::string::npos) {// for primitives this is a first
+ indx = 1;
+ } else {
+ aSubString = aSubString.substr(n+1);
+ indx = atoi(aSubString.c_str());
+ }
TNaming_Iterator anItL(theNS);
for(int i = 1; anItL.More(); anItL.Next(), i++) {
const std::string& theSubShapeName, std::shared_ptr<Model_Document> theDoc)
{
TopoDS_Shape aFace;
- std::string::size_type n, nb = theSubShapeName.rfind('/');
- if (nb == std::string::npos) nb = 0;
- std::string aSubString = theSubShapeName.substr(nb + 1);
- n = aSubString.rfind('_');
- if (n != std::string::npos) {
- std::string aSubStr2 = aSubString.substr(0, n);
- aSubString = theSubShapeName.substr(0, nb + 1);
- aSubString = aSubString + aSubStr2;
- } else
- aSubString = theSubShapeName;
-
- const TDF_Label& aLabel = theDoc->findNamingName(aSubString);
+ //std::string::size_type n, nb = theSubShapeName.rfind('/');
+ //if (nb == std::string::npos) nb = 0;
+ //std::string aSubString = theSubShapeName.substr(nb + 1);
+ std::string aSubString = theSubShapeName;
+
+ TDF_Label aLabel = theDoc->findNamingName(aSubString);
+ if (aLabel.IsNull()) { // try to remove additional artificial suffix
+ std::string::size_type n = aSubString.rfind('_');
+ if (n != std::string::npos) {
+ aSubString = aSubString.substr(0, n);
+ aLabel = theDoc->findNamingName(aSubString);
+ }
+ }
if(aLabel.IsNull()) return aFace;
Handle(TNaming_NamedShape) aNS;
if(aLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
// possible this is body where postfix is added to distinguish several shapes on the same label
int aSubShapeId = -1; // -1 means sub shape not found
// for result body the name wihtout "_" has higher priority than with it: it is always added
- if ((!aCont.get() || (aCont->groupName() == ModelAPI_ResultBody::group())) &&
+ if ((!aCont.get()/* || (aCont->groupName() == ModelAPI_ResultBody::group())*/) &&
aContName == aSubShapeName) {
size_t aPostIndex = aContName.rfind('_');
if (aPostIndex != std::string::npos) {
return true;
} else if (aSubShapeId > 0) { // try to find sub-shape by the index
TopExp_Explorer anExp(aCont->shape()->impl<TopoDS_Shape>(), aType);
- for(; aSubShapeId > 0 && anExp.More(); aSubShapeId--) {
+ for(; aSubShapeId > 1 && anExp.More(); aSubShapeId--) {
anExp.Next();
}
if (anExp.More()) {
protected:
/// Gets the stored name from the document
- std::string getShapeName(std::shared_ptr<Model_Document> theDoc, const TopoDS_Shape& theShape);
+ std::string getShapeName(std::shared_ptr<Model_Document> theDoc, const TopoDS_Shape& theShape,
+ const bool theAddContextName);
};
#endif
aResult<<": "<<aCount<<std::endl;
}
// output the main characteristics
- aResult<<"Volume: "<<setprecision(2)<<GeomAlgoAPI_ShapeTools::volume(theShape)<<std::endl;
+ if (GeomAlgoAPI_ShapeTools::volume(theShape) > 1.e-7) {
+ aResult<<"Volume: "<<std::fixed<<setprecision(3)<<GeomAlgoAPI_ShapeTools::volume(theShape)<<std::endl;
+ }
std::shared_ptr<GeomAPI_Pnt> aCenter = GeomAlgoAPI_ShapeTools::centreOfMass(theShape);
aResult<<"Center of mass: ";
double aCenterVals[3] = {aCenter->x(), aCenter->y(), aCenter->z()};