Tue, 06/18/2002 - 21:17
Forums:
Hi Everybody!
Where can i find some information on Shape Attributes? The doc in Application Framework User $ Guide is not enought clear for me...
Is there an exemple somewhere?
Here a description on what i want to do: Suppose a have three solid shapes.The third one is the intersection of the others:
TopoDS_Solid S1..(a box).
TopoDS_Solid S2...
TopoDS_Shape S3 = BRepAlgoAPI_Common(S1,S2)
I would like to give a name to the six faces of the Solid S1. And I Would like to be able to pass those names in the Shape S3 if the faces are still in the shape S3 (the faces can be modify).
Is it possible to do that?
Genevieve
Fri, 06/21/2002 - 12:20
Yes, it is possible to do that, but you have to do it manually. Every BRepBuilderAPI_MakeShape derived class has Modified, Generated, IsDeleted methods which can be used to get the subshapes - like faces - derived from an original subshape after the operation. I hope this information will help you.
Fri, 06/21/2002 - 22:16
Thank you ninja for your answer...
I would have hope that OCC provide a methods or class to pass the attributes automatically, but i understand now...
I send a piece of code that help me understand, if it can help other i'll be happy (the code is not bug proof) :
/Creer un document
Handle(TDocStd_Document) MonDocument = new TDocStd_Document("MonDoc");
TDF_Label labelShapeFinal = MonDocument->Main().FindChild(1,Standard_True);
//box1
TDF_Label labelBox1 = labelDistributeur.FindChild(1,Standard_True);
BRepPrimAPI_MakeBox FaireBox(gp_Pnt(0,0,0),10,12,6);
TopoDS_Solid Box1 = FaireBox.Solid();
//load shape into framework
TDF_Label labelShapeBox1 = labelBox1.FindChild(1,Standard_True);
TNaming_Builder aBuilder1(labelShapeBox1);
aBuilder1.Generated(Box1);
TDF_Label labelTopFace = labelShapeBox1.FindChild(1,Standard_True);
TNaming_Builder aBuilder2(labelTopFace);
TopoDS_Face Box1TopFace = FaireBox.TopFace();
aBuilder2.Generated(Box1TopFace);
TDF_Label labelRightFace = labelShapeBox1.FindChild(2,Standard_True);
TNaming_Builder aBuilder3(labelRightFace);
TopoDS_Face Box1RightFace = FaireBox.RightFace();
aBuilder3.Generated(Box1RightFace);
//box2
TDF_Label labelBox2 = labelDistributeur.FindChild(2,Standard_True);
BRepPrimAPI_MakeBox FaireBox2(gp_Pnt(1,6,1),5,10,3);
TopoDS_Solid Box2 = FaireBox2.Solid();
//load shape into framework
TDF_Label labelShapeBox2 = labelBox2.FindChild(1,Standard_True);
TNaming_Builder aBuilder13(labelShapeBox2);
aBuilder13.Generated(FaireBox2.Solid());
TDF_Label labelTopFaceBox2 = labelShapeBox2.FindChild(1,Standard_True);
TNaming_Builder aBuilder14(labelTopFaceBox2);
TopoDS_Face Box2TopFace = FaireBox2.TopFace();
aBuilder14.Generated(Box2TopFace);
TDF_Label labelRightFaceBox2 = labelShapeBox2.FindChild(5,Standard_True);
TNaming_Builder aBuilder11(labelRightFaceBox2);
TopoDS_Face Box2RightFace = FaireBox2.RightFace();
aBuilder11.Generated(Box2RightFace);
//Common operation
TDF_Label labelOperation = labelDistributeur.FindChild(3,Standard_True);
BRepAlgoAPI_Common FaireOperation(FaireBox.Solid(),FaireBox2.Solid());
TopoDS_Shape BlocFinal = FaireOperation.Shape();
TDF_Label labelShapeOperation = labelOperation.FindChild(1,Standard_True);
TNaming_Builder aBuilder20(labelShapeOperation);
aBuilder20.Generated(TopoDS::Solid(BlocFinal));
//Follow what append with every named faces of basic shapes (box1 and box2)
TopTools_ListOfShape ListeShapes();
TopTools_ListOfShape FacesFromOperation();
TopoDS_Face FirstFace = Box1TopFace;
TDF_Label NewLabel;
if ( FaireOperation.IsDeleted(FirstFace))
{
NewLabel = labelShapeOperation.FindChild(i,Standard_True);
TNaming_Builder aBuilder(NewLabel);
aBuilder.Delete(FirstFace);
}
else
{
ListeShapes = FaireOperation.Modified(FirstFace);
if (ListeShapes.Extent())
{
for (int j=1;j<=ListeShapes.Extent();j++)
{
TopoDS_Face LastFace = TopoDS::Face(ListeShapes.First());
NewLabel = TDF_TagSource::NewChild(labelShapeOperation);
TNaming_Builder aBuilder(NewLabel);
aBuilder.Modify(FirstFace,LastFace);
ListeShapes.RemoveFirst();
FacesFromOperation.Append(LastFace);
}
}
else
{
//Faces are identical
NewLabel = TDF_TagSource::NewChild(labelShapeOperation);
TNaming_Builder aBuilder(NewLabel);
aBuilder.Modify(FirstFace,FirstFace);// presently i don't know how to say there is no modification
FacesFromOperation.Append(FirstFace);
}
}
TDF_Label LabelTopFaceBox1Fin = NewLabel;
FirstFace = Box1RightFace;
// Reuse the code
if ( FaireOperation.IsDeleted(FirstFace))
{
NewLabel = labelShapeOperation.FindChild(i,Standard_True);
TNaming_Builder aBuilder(NewLabel);
aBuilder.Delete(FirstFace);
}
else
{
ListeShapes = FaireOperation.Modified(FirstFace);
if (ListeShapes.Extent())
{
for (int j=1;j<=ListeShapes.Extent();j++)
{
TopoDS_Face LastFace = TopoDS::Face(ListeShapes.First());
NewLabel = TDF_TagSource::NewChild(labelShapeOperation);
TNaming_Builder aBuilder(NewLabel);
aBuilder.Modify(FirstFace,LastFace);
ListeShapes.RemoveFirst();
FacesFromOperation.Append(LastFace);
}
}
else
{
//Faces are identical
NewLabel = TDF_TagSource::NewChild(labelShapeOperation);
TNaming_Builder aBuilder(NewLabel);
aBuilder.Modify(FirstFace,FirstFace);// presently i don't know how to say there is no modification
FacesFromOperation.Append(FirstFace);
}
}
TDF_Label LabelRightFaceBox1Fin = NewLabel;
etc....
Now if i iterate on a label, i can follow the evolution:
TNaming_Iterator itL(aLabel);
for(;itL.More();itL.Next())
{
if (!itL.NewShape().IsNull())
{
aS = itL.NewShape(); //get New Shape if exist
NbShapes++;
NS = TNaming_Tool::NamedShape(aS,aLabel);
TNaming::Print(NS->Evolution(),cout); // print aNew Shape evolution
}
if (!itL.OldShape().IsNull())
{
aS = itL.OldShape(); //get old Shape if exist
NbShapes++;
NS = TNaming_Tool::NamedShape(aS,aLabel);
TNaming::Print(NS->Evolution(),cout);
}
}
Thu, 12/12/2002 - 23:04
Hey, thanks for posting the code, it's very useful.
Merci beaucoup!
Thu, 10/08/2009 - 20:15
It's GREAT, it's very USEFUL!!
THANK YOU! Thank you very much!! Thank you for sharing this precious code!!!
Saretto
Sun, 05/12/2024 - 03:02
Thank you so much for your code sample.
It is a huge help.