summaryrefslogtreecommitdiff
path: root/src/DNaming/DNaming_ToolsCommands.cxx
blob: 862fe45a44a94fd573663cdcbdfdf543d98da2cb (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
// File:	DNaming_ToolsCommands.cxx
// Created:	Thu Jun 24 18:38:25 1999
// Author:	Sergey ZARITCHNY
//		<szy@philipox.nnov.matra-dtv.fr>

#include <Draw_Interpretor.hxx>
#include <Draw.hxx>
#include <DBRep.hxx>
#include <DNaming.hxx>
#include <BRepTools.hxx>
#include <TopoDS_Face.hxx>
#include <TopLoc_Location.hxx>
#include <BRep_Builder.hxx>
#include <gp_Pnt.hxx>
#include <TopExp_Explorer.hxx>
#include <TCollection_AsciiString.hxx>
#include <TopAbs.hxx>
#include <TNaming_Translator.hxx>
#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
#include <DNaming_DataMapOfShapeOfName.hxx>
#include <DNaming_DataMapIteratorOfDataMapOfShapeOfName.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_MapIteratorOfMapOfShape.hxx>
//=======================================================================
//function : DNaming_CheckHasSame 
//purpose  : CheckIsSame  Shape1 Shape2 
//           - for test ShapeCopy mechanism
//=======================================================================

static Standard_Integer DNaming_CheckHasSame (Draw_Interpretor& di,
					      Standard_Integer nb, 
					      const char** arg)
{
  if(nb < 4) return 1;
  TopoDS_Shape S1 = DBRep::Get(arg[1]);
  if ( S1.IsNull() ) {
    BRep_Builder aBuilder;
    BRepTools::Read( S1, arg[1], aBuilder);
    }
  
  TopoDS_Shape S2 = DBRep::Get(arg[2]);
  if ( S2.IsNull() ) {
    BRep_Builder aBuilder;
    BRepTools::Read( S2, arg[2], aBuilder);
    }
  char M[8];
  strcpy(M, arg[3]);
  strtok(M, " \t");
  TopAbs_ShapeEnum mod = TopAbs_FACE;
  if(M[0] == 'F' || M[0] == 'f')
    mod = TopAbs_FACE;
  else if(M[0] == 'E' || M[0] == 'e')
    mod = TopAbs_EDGE;
  else if(M[0] == 'V' || M[0] == 'v')
    mod = TopAbs_VERTEX;
  else 
    return 1;

  TopExp_Explorer Exp1, Exp2;

  TopTools_MapOfShape M1, M2;
  for(Exp1.Init(S1, mod);Exp1.More();Exp1.Next()) {
    M1.Add(Exp1.Current());
  }
  for(Exp2.Init(S2, mod);Exp2.More();Exp2.Next()) {
    M2.Add(Exp2.Current());
  }

  TopTools_MapIteratorOfMapOfShape itr1(M1);
  TopTools_MapIteratorOfMapOfShape itr2;
  for(;itr1.More();itr1.Next()) {
    const TopoDS_Shape& s1 = itr1.Key();
    
    for(itr2.Initialize(M2);itr2.More();itr2.Next()) {
      const TopoDS_Shape& s2 = itr2.Key();
      if(s1.IsSame(s2))
	di << "Shapes " << arg[1]<< " and "<< arg[2]<< " have SAME subshapes" <<"\n";
    }
  }

  return 0;
}           
//=======================================================================
//function : DNaming_TCopyShape
//purpose  : CopyShape  Shape1 [Shape2 ...] 
//           - for test ShapeCopy mechanism
//=======================================================================

static Standard_Integer DNaming_TCopyShape (Draw_Interpretor& di,
					      Standard_Integer nb, 
					      const char** arg)
{
  TNaming_Translator TR;
  if(nb < 2) return (1);

  DNaming_DataMapOfShapeOfName aDMapOfShapeOfName;
  for(Standard_Integer i= 1;i < nb; i++) {
    TopoDS_Shape S = DBRep::Get(arg[i]);
    TCollection_AsciiString name(arg[i]);
    name.AssignCat("_c");
    if ( S.IsNull() ) {
      BRep_Builder aBuilder;
      BRepTools::Read( S, arg[i], aBuilder);
    }
    
// Add to Map                
    if(S.IsNull()) return(1);
    else {
      aDMapOfShapeOfName.Bind(S, name);
      TR.Add(S);
    }
  } // for ...

// PERFORM 
  TR.Perform();

  if(TR.IsDone()){
    di << "DNaming_CopyShape:: Copy is Done " << "\n";

    DNaming_DataMapIteratorOfDataMapOfShapeOfName itrn(aDMapOfShapeOfName);
    for(;itrn.More();itrn.Next()) {
      TCollection_AsciiString name = itrn.Value();
      const TopoDS_Shape& Result = TR.Copied(itrn.Key());
      DBRep::Set(name.ToCString(), Result);
      di.AppendElement(name.ToCString());
    }
    return 0;
  }
  di << "DNaming_CopyShape : Error" << "\n";
  return 1;
}

//=======================================================================
//function : ToolsCommands
//purpose  : 
//=======================================================================

void DNaming::ToolsCommands (Draw_Interpretor& theCommands)
{  

  static Standard_Boolean done = Standard_False;
  if (done) return;
  done = Standard_True;
  const char* g = "Naming data commands " ;

  theCommands.Add ("CopyShape", 
                   "CopyShape (Shape1 [Shape2] ...)",
		   __FILE__, DNaming_TCopyShape, g); 

  theCommands.Add ("CheckSame", 
                   "CheckSame (Shape1 Shape2 ExploMode[F|E|V])",
		   __FILE__, DNaming_CheckHasSame, g); 
 
}