summaryrefslogtreecommitdiff
path: root/src/TestTopOpe/TestTopOpe_DSACommands.cxx
blob: fb6bc2d65c39ddca6b4d5a8366a207f203ce13c5 (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
// File:	TestTopOpe_DSACommands.cxx
// Created:	Mon Dec  1 11:37:25 1997
// Author:	Prestataire Mary FABIEN
//		<fbi@langdox.paris1.matra-dtv.fr>


#include <TestTopOpe.ixx>
#include <BRepAlgo_DSAccess.hxx>
#include <DBRep.hxx>
#include <TopOpeBRepDS_define.hxx>

Standard_Integer DSACCESSCOMMANDS(Draw_Interpretor& interpretor,Standard_Integer na, const char** a)
{ 
  static BRepAlgo_DSAccess DSA;
//  Standard_Integer i;

  if (!strcmp(a[0],"dsload"))
    if (na == 3) {
      TopoDS_Shape SS1 = DBRep::Get(a[1]);
      TopoDS_Shape& S1 = SS1;
      TopoDS_Shape SS2 = DBRep::Get(a[2]);
      TopoDS_Shape& S2 = SS2;
      TestTopOpe::CurrentDS(DSA.DS());
      DSA.Load(S1, S2);
      return 0;
    }
    else 
      return 0;

  else if(!strcmp(a[0],"dsinit")) {
    DSA.Init();
  }
  else if(!strcmp(a[0],"dsinters"))
    if (na == 4)
      if(!strcmp(a[1],"-sd")) {
	const TopoDS_Shape& S1 = DBRep::Get(a[2]);
	const TopoDS_Shape& S2 = DBRep::Get(a[3]);
	DSA.SameDomain(S1, S2);
      }
      else 
	return 0;
    else {
      if(na == 3) {
	const TopoDS_Shape& S1 = DBRep::Get(a[1]);
	const TopoDS_Shape& S2 = DBRep::Get(a[2]);
	DSA.Intersect(S1, S2);
      }
      else
	if(na == 1) 
	  DSA.Intersect();
    }
  else if(!strcmp(a[0],"dsgetsect")) {
    if((na == 2) || (na == 4)) {
      TopoDS_Shape EmptyShape;
      const TopoDS_Shape& S1 = ((na == 2) ? EmptyShape : DBRep::Get(a[2]));
      const TopoDS_Shape& S2 = ((na == 2) ? EmptyShape : DBRep::Get(a[3]));
      const TopTools_ListOfShape& list = 
	((na == 2) ? DSA.GetSectionEdgeSet() : 
	 DSA.GetSectionEdgeSet(S1, S2));
      Standard_Integer index = 1;
      if(list.Extent() > 1) {
	TopTools_ListIteratorOfListOfShape it(list);
	for(; it.More(); it.Next(), index++) {
	  TCollection_AsciiString enam(a[1]);
	  enam=enam + "_" + TCollection_AsciiString(index);
	  DBRep::Set(enam.ToCString(),it.Value());
	}
      }
      else
	if(list.Extent() == 1) {
	  TCollection_AsciiString enam(a[1]);
	  DBRep::Set(enam.ToCString(),list.First());
	}	
	else
	  return 0;
    }
  }
  
  else if(!strcmp(a[0],"dssuppsect")) {
    if(na == 2) {
      const TopoDS_Shape& S = DBRep::Get(a[1]);
      DSA.SuppressEdgeSet(S);
    }
    else
      return 0;
  }
  
  else if(!strcmp(a[0],"dsperform")) {
    if(na == 3) {
      TopoDS_Shape S;
      TCollection_AsciiString enam(a[1]);
      if(!strcmp(enam.ToCString(),"fus")) 
	S = DSA.Merge(TopAbs_OUT, TopAbs_OUT);
      else if(!strcmp(enam.ToCString(),"c12")) 
	S = DSA.Merge(TopAbs_OUT, TopAbs_IN);
      else if(!strcmp(enam.ToCString(),"c21")) 
	S = DSA.Merge(TopAbs_IN, TopAbs_OUT);
      else if(!strcmp(enam.ToCString(),"com")) 
	S = DSA.Merge(TopAbs_IN, TopAbs_IN);
      DBRep::Set(a[2], S);
      TopOpeBRepDS_DataStructure& DS = DSA.DS()->ChangeDS();
      Standard_Integer i,nbsh = DS.NbShapes();
      for(i = 1;i<=nbsh;i++) {
	TopTools_ListOfShape& los = DS.ChangeShapeSameDomain(i);
	TopTools_ListIteratorOfListOfShape li(los);
	for(; li.More(); li.Next()) {
      li.Value();
	}
      }
    }
    else
      return 0;
  }
  
  else if(!strcmp(a[0],"dshelp")) {

    interpretor<<"\n";
    interpretor<<"  dsinit"<<"\n";
    interpretor<<"  dsload shape1 shape2"<<"\n";
    interpretor<<"  dsinters [-sd] [f1 f2]"<<"\n";
    interpretor<<"    if -sd, the faces are samedomain"<<"\n";
    interpretor<<"    no argument = intersect two input Shapes"<<"\n";
    interpretor<<"  dsgetsect result [f1 f2] (result = compound)"<<"\n";
    interpretor<<"  dssuppsect comp"<<"\n";
    interpretor<<"  dsperform fus/c12/c21/com resultShape "<<"\n";
    interpretor<<"\n";

    return 0;
  }
  return 0;
}
//=======================================================================
//function : BOOPCommands
//purpose  : 
//=======================================================================
void TestTopOpe::DSACommands(Draw_Interpretor& theCommands)
{
  const char* g = "TestTopOpe DSACommands";
  theCommands.Add("dsinit","Taper dshelp",__FILE__,DSACCESSCOMMANDS,g);
  theCommands.Add("dsload","Taper dshelp",__FILE__,DSACCESSCOMMANDS,g);
  theCommands.Add("dsinters","Taper dshelp",__FILE__,DSACCESSCOMMANDS,g);
  theCommands.Add("dsgetsect","Taper dshelp",__FILE__,DSACCESSCOMMANDS,g);
  theCommands.Add("dssuppsect","Taper dshelp",__FILE__,DSACCESSCOMMANDS,g);
  theCommands.Add("dsperform","Taper dshelp",__FILE__,DSACCESSCOMMANDS,g);
  theCommands.Add("dshelp","Taper dshelp",__FILE__,DSACCESSCOMMANDS,g);
}