summaryrefslogtreecommitdiff
path: root/src/BOPTest/BOPTest_WSplitCommands.cxx
blob: 6174edef3176f7fb29e9298384387e4c24426fae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// File:	BOPTest_WSplitCommands.cxx
// Created:	10:45:01 2000
// Author:	Peter KURNEV
//		<pkv@irinox>


#include <BOPTest.ixx>

#include <stdio.h>

#include <BOPTest_DrawableShape.hxx>

#include <DBRep.hxx>
#include <DBRep_DrawableShape.hxx>

#include <Draw.hxx>
#include <Draw_Color.hxx>

#include <TCollection_AsciiString.hxx>

#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Wire.hxx>
#include <TopAbs_ShapeEnum.hxx>

#include <BOP_WireSplitter.hxx>

#include <BRep_Builder.hxx>
#include <TopoDS_Compound.hxx>

#include <TopoDS_Shell.hxx>
#include <BOP_ShellSplitter.hxx>

#include <BOPTColStd_ListOfListOfShape.hxx>
#include <BOPTColStd_ListIteratorOfListOfListOfShape.hxx>

#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>




static   Standard_Integer bwsplit  (Draw_Interpretor&, Standard_Integer, const char** );
static   Standard_Integer bssplit  (Draw_Interpretor&, Standard_Integer, const char** );


//=======================================================================
//function : WSplitCommands
//purpose  : 
//=======================================================================
  void  BOPTest::WSplitCommands(Draw_Interpretor& theCommands)
{
  static Standard_Boolean done = Standard_False;
  if (done) 
    return;

  done = Standard_True;
  // Chapter's name
  const char* g = "CCR commands";

  theCommands.Add("bwsplit"   , "Use bwsplit> Face"   , __FILE__, bwsplit  , g);
  theCommands.Add("bssplit"   , "Use bssplit> Shell"  , __FILE__, bssplit  , g);
}

//=======================================================================
//function : bssplit
//purpose  : 
//=======================================================================
Standard_Integer bssplit (Draw_Interpretor& di, 
			  Standard_Integer n, 
			  const char** a)
{
  if (n!=2) {
    di << " Use bssplit> Shell\n";
    return 1;
  }
  
  TopoDS_Shape S = DBRep::Get(a[1]);
  
  if (S.IsNull()) {
    di << " Null shape is not allowed \n";
    return 1;
  }

  Standard_Boolean anIsDone, anIsNothingToDo ;

  TopAbs_ShapeEnum aT;
  aT=S.ShapeType();
  if (aT!=TopAbs_SHELL) {
    di << " Shape Type must be SHELL\n";
    return 1;
  }

  const TopoDS_Shell& aSh = TopoDS::Shell(S);

  BOP_ShellSplitter aShellSplitter;
  aShellSplitter.SetShell(aSh);
  aShellSplitter.DoWithShell ();
  anIsDone=aShellSplitter.IsDone();
  di << " aShellSplitter.IsDone=" << (Standard_Integer) anIsDone << "\n";
  
  anIsNothingToDo=aShellSplitter.IsNothingToDo();
  di << " IsNothingToDo=" << (Standard_Integer) anIsNothingToDo << "\n";

  if (!anIsDone) { 
    return 0;
  }
  if (anIsNothingToDo) {
    return 0;
  }
  //
  Standard_Integer i=1;
  BRep_Builder BB;
  const BOPTColStd_ListOfListOfShape& aSSS=aShellSplitter.Shapes();
  BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
  for (; aWireIt.More(); aWireIt.Next(), ++i) {
    TopoDS_Compound aCompound;
    BB.MakeCompound(aCompound);

    const TopTools_ListOfShape& aListEd=aWireIt.Value();

    TopTools_ListIteratorOfListOfShape anIt(aListEd);
    for (; anIt.More(); anIt.Next()) {
      const TopoDS_Shape& aE=anIt.Value();
      BB.Add(aCompound, aE);
    }
    TCollection_AsciiString aName(a[1]), aDef("_"), anI(i), aRName;
    aRName=aName;
    aRName=aRName+aDef;
    aRName=aRName+anI;

    DBRep::Set (aRName.ToCString(), aCompound);
    di << aRName.ToCString() << "\n";
  }

  return 0;
}

//=======================================================================
//function : bwsplit
//purpose  : 
//=======================================================================
Standard_Integer bwsplit (Draw_Interpretor& di, 
			  Standard_Integer n, 
			  const char** a)
{
  if (n!=2) {
    di << " Use bwsplit> Face\n";
    return 1;
  }
  
  TopoDS_Shape S = DBRep::Get(a[1]);
  
  if (S.IsNull()) {
    di << " Null shape is not allowed \n";
    return 1;
  }

  Standard_Boolean anIsDone, anIsNothingToDo ;

  TopAbs_ShapeEnum aT;
  aT=S.ShapeType();
  if (aT!=TopAbs_FACE) {
    di << " Shape Type must be FACE\n";
    return 1;
  }

  const TopoDS_Face& aF = TopoDS::Face(S);

  BOP_WireSplitter aWireSplitter;
  aWireSplitter.SetFace(aF);
  aWireSplitter.DoWithFace ();
  anIsDone=aWireSplitter.IsDone();
  di << " aWireSplitter.IsDone=" << (Standard_Integer) anIsDone << "\n";
  
  anIsNothingToDo=aWireSplitter.IsNothingToDo();
  di << " IsNothingToDo=" << (Standard_Integer) anIsNothingToDo << "\n";

  if (!anIsDone) { 
    return 0;
  }
  if (anIsNothingToDo) {
    return 0;
  }
  //
  Standard_Integer i=1;
  BRep_Builder BB;
  const BOPTColStd_ListOfListOfShape& aSSS=aWireSplitter.Shapes();
  BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
  for (; aWireIt.More(); aWireIt.Next(), ++i) {
    TopoDS_Compound aCompound;
    BB.MakeCompound(aCompound);

    const TopTools_ListOfShape& aListEd=aWireIt.Value();

    TopTools_ListIteratorOfListOfShape anIt(aListEd);
    for (; anIt.More(); anIt.Next()) {
      const TopoDS_Shape& aE=anIt.Value();
      BB.Add(aCompound, aE);
    }
    TCollection_AsciiString aName(a[1]), aDef("_"), anI(i), aRName;
    aRName=aName;
    aRName=aRName+aDef;
    aRName=aRName+anI;

    DBRep::Set (aRName.ToCString(), aCompound);
    di << aRName.ToCString() << "\n";
  }
  return 0;
}