0022898: IGES import fails in german environment
[occt.git] / src / BRepTest / BRepTest_ExtremaCommands.cxx
1 // Created on: 1995-09-08
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21 // modified by mps (juillet 96) : ajout de la commande distmini
22
23 #include <DBRep.hxx>
24 #include <BRepTest.hxx>
25 #include <gp_Pnt.hxx>
26 #include <TopoDS_Shape.hxx>
27 #include <TopoDS_Edge.hxx>
28 #include <BRepExtrema_Poly.hxx>
29 #include <BRepExtrema_DistShapeShape.hxx>
30 #include <BRepLib_MakeEdge.hxx>
31 #include <BRepLib_MakeEdge.hxx>
32 #include <BRepLib_MakeVertex.hxx>
33 #include <Draw.hxx>
34 #include <Draw_Interpretor.hxx>
35 //#ifdef WNT
36 #include <stdio.h>
37 //#endif
38
39 //=======================================================================
40 //function : distance
41 //purpose  : 
42 //=======================================================================
43
44 static Standard_Integer distance (Draw_Interpretor& di,
45                                   Standard_Integer n,
46                                   const char** a)
47 {
48   if (n < 3) return 1;
49
50   const char *name1 = a[1];
51   const char *name2 = a[2];
52
53   TopoDS_Shape S1 = DBRep::Get(name1);
54   TopoDS_Shape S2 = DBRep::Get(name2);
55   if (S1.IsNull() || S2.IsNull()) return 1;
56   gp_Pnt P1,P2;
57   Standard_Real D;
58   if (!BRepExtrema_Poly::Distance(S1,S2,P1,P2,D)) return 1;
59   //cout << " distance : " << D << endl;
60   di << " distance : " << D << "\n";
61   TopoDS_Edge E = BRepLib_MakeEdge(P1,P2);
62   DBRep::Set("distance",E);
63   return 0;
64 }
65 static Standard_Integer distmini(Draw_Interpretor& di, Standard_Integer n, const char** a)
66
67   Standard_Integer i1;
68 //  gp_Pnt P;
69
70   if (n != 4) return 1;
71
72   const char *ns1 = (a[2]), *ns2 = (a[3]), *ns0 = (a[1]);
73   TopoDS_Shape S1(DBRep::Get(ns1)), S2(DBRep::Get(ns2))  ;
74   BRepExtrema_DistShapeShape dst(S1 ,S2 );
75
76
77   if (dst.IsDone()) 
78       { 
79 #ifdef DEB
80          //dst.Dump(cout);
81         Standard_SStream aSStream;
82         dst.Dump(aSStream);
83         di << aSStream;
84 #endif
85
86          char named[100];
87          Sprintf(named, "%s%s" ,ns0,"_val");
88          char* tempd = named;
89          Draw::Set(tempd,dst.Value());
90          di << named << " ";
91
92          for (i1=1; i1<= dst.NbSolution(); i1++)
93            {
94              gp_Pnt P1,P2;
95              P1 = (dst.PointOnShape1(i1));
96              P2 = (dst.PointOnShape2(i1));
97              if (dst.Value()<=1.e-9) 
98              {
99               TopoDS_Vertex V =BRepLib_MakeVertex(P1);
100               char namev[100];
101               if (i1==1) 
102               Sprintf(namev, "%s" ,ns0);
103               else Sprintf(namev, "%s%d" ,ns0,i1);
104               char* tempv = namev;
105               DBRep::Set(tempv,V);
106               di << namev << " ";
107               }
108              else
109              {char name[100];
110               TopoDS_Edge E = BRepLib_MakeEdge (P1, P2);
111               if (i1==1)
112               {Sprintf(name,"%s",ns0);}
113               else {Sprintf(name,"%s%d",ns0,i1);}
114               char* temp = name;
115               DBRep::Set(temp,E);
116               di << name << " " ;
117              }
118            }
119       }
120   
121   else di << "probleme"<< "\n";
122   //else cout << "probleme"<< endl;
123   return 0;
124 }
125
126 //=======================================================================
127 //function : ExtremaCommands
128 //purpose  : 
129 //=======================================================================
130
131 void  BRepTest::ExtremaCommands(Draw_Interpretor& theCommands)
132 {
133   static Standard_Boolean done = Standard_False;
134   if (done) return;
135   done = Standard_True;
136
137   const char* g = "TOPOLOGY Extrema commands";
138
139   theCommands.Add("dist","dist Shape1 Shape2"   ,__FILE__,distance,g);
140
141   
142   theCommands.Add("distmini",
143                   "distmini name Shape1 Shape2",
144                   __FILE__,
145                   distmini,g);
146 }
147
148
149
150
151
152
153
154
155
156
157
158