1 // Created on: 1991-04-09
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Standard_NullObject.hxx>
19 #include <TopoDS_Builder.hxx>
20 #include <TopoDS_Compound.hxx>
21 #include <TopoDS_CompSolid.hxx>
22 #include <TopoDS_FrozenShape.hxx>
23 #include <TopoDS_ListIteratorOfListOfShape.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <TopoDS_Shell.hxx>
26 #include <TopoDS_Solid.hxx>
27 #include <TopoDS_TCompound.hxx>
28 #include <TopoDS_TShape.hxx>
29 #include <TopoDS_TWire.hxx>
30 #include <TopoDS_UnCompatibleShapes.hxx>
31 #include <TopoDS_Wire.hxx>
33 //=======================================================================
34 //function : MakeShape
35 //purpose : Make a Shape from a TShape
36 //=======================================================================
37 void TopoDS_Builder::MakeShape (TopoDS_Shape& S,
38 const Handle(TopoDS_TShape)& T) const
41 S.Location(TopLoc_Location());
42 S.Orientation(TopAbs_FORWARD);
46 //=======================================================================
48 //purpose : insert aComponent in aShape
49 //=======================================================================
51 void TopoDS_Builder::Add (TopoDS_Shape& aShape,
52 const TopoDS_Shape& aComponent) const
54 // From now the Component cannot be edited
55 aComponent.TShape()->Free(Standard_False);
57 // Note that freezing aComponent before testing if aShape is free
58 // prevents from self-insertion
59 // but aShape will be frozen when the Exception is raised
62 static const unsigned int aTb[9]=
65 (1<<((unsigned int)TopAbs_COMPOUND)),
67 (1<<((unsigned int)TopAbs_COMPOUND)),
69 (1<<((unsigned int)TopAbs_COMPOUND)) |
70 (1<<((unsigned int)TopAbs_COMPSOLID)),
72 (1<<((unsigned int)TopAbs_COMPOUND)) |
73 (1<<((unsigned int)TopAbs_SOLID)),
75 (1<<((unsigned int)TopAbs_COMPOUND)) |
76 (1<<((unsigned int)TopAbs_SHELL)),
78 (1<<((unsigned int)TopAbs_COMPOUND)) |
79 (1<<((unsigned int)TopAbs_FACE)),
81 (1<<((unsigned int)TopAbs_COMPOUND)) |
82 (1<<((unsigned int)TopAbs_SOLID)) |
83 (1<<((unsigned int)TopAbs_WIRE)),
85 (1<<((unsigned int)TopAbs_COMPOUND)) |
86 (1<<((unsigned int)TopAbs_SOLID)) |
87 (1<<((unsigned int)TopAbs_FACE)) |
88 (1<<((unsigned int)TopAbs_EDGE)),
93 const unsigned int iC=(unsigned int)aComponent.ShapeType();
94 const unsigned int iS=(unsigned int)aShape.ShapeType();
96 if ((aTb[iC] & (1<<iS)) != 0) {
97 TopoDS_ListOfShape& L = aShape.TShape()->myShapes;
99 TopoDS_Shape& S = L.Last();
101 // compute the relative Orientation
102 if (aShape.Orientation() == TopAbs_REVERSED)
105 // and the Relative Location
106 const TopLoc_Location& aLoc=aShape.Location();
107 if (!aLoc.IsIdentity())
108 S.Move(aLoc.Inverted());
110 // Set the TShape as modified.
111 aShape.TShape()->Modified(Standard_True);
114 throw TopoDS_UnCompatibleShapes("TopoDS_Builder::Add");
118 throw TopoDS_FrozenShape("TopoDS_Buider::Add");
123 //=======================================================================
125 //purpose : Remove a Shape from an other one
126 //=======================================================================
128 void TopoDS_Builder::Remove (TopoDS_Shape& aShape,
129 const TopoDS_Shape& aComponent) const
131 // check if aShape is not Frozen
132 TopoDS_FrozenShape_Raise_if (!aShape.Free(),"TopoDS_Builder::Remove");
134 // compute the relative Orientation and Location of aComponent
135 TopoDS_Shape S = aComponent;
136 if (aShape.Orientation() == TopAbs_REVERSED)
138 S.Location(S.Location().Predivided(aShape.Location()));
140 TopoDS_ListOfShape& L = aShape.TShape()->myShapes;
141 TopoDS_ListIteratorOfListOfShape It(L);
143 if (It.Value() == S) {
145 aShape.TShape()->Modified(Standard_True);