0024572: Improvement performance of BRepExtrema_DistShapeShape
[occt.git] / src / BRepTest / BRepTest_ExtremaCommands.cxx
CommitLineData
b311480e 1// Created on: 1995-09-08
2// Created by: Modelistation
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
7fd59977 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17// modified by mps (juillet 96) : ajout de la commande distmini
18
19#include <DBRep.hxx>
20#include <BRepTest.hxx>
7fd59977 21#include <BRepExtrema_Poly.hxx>
22#include <BRepExtrema_DistShapeShape.hxx>
23#include <BRepLib_MakeEdge.hxx>
7fd59977 24#include <BRepLib_MakeVertex.hxx>
25#include <Draw.hxx>
762b6cec 26
7fd59977 27//#ifdef WNT
28#include <stdio.h>
29//#endif
30
31//=======================================================================
32//function : distance
33//purpose :
34//=======================================================================
35
36static Standard_Integer distance (Draw_Interpretor& di,
37 Standard_Integer n,
38 const char** a)
39{
40 if (n < 3) return 1;
41
42 const char *name1 = a[1];
43 const char *name2 = a[2];
44
45 TopoDS_Shape S1 = DBRep::Get(name1);
46 TopoDS_Shape S2 = DBRep::Get(name2);
47 if (S1.IsNull() || S2.IsNull()) return 1;
48 gp_Pnt P1,P2;
49 Standard_Real D;
50 if (!BRepExtrema_Poly::Distance(S1,S2,P1,P2,D)) return 1;
51 //cout << " distance : " << D << endl;
52 di << " distance : " << D << "\n";
53 TopoDS_Edge E = BRepLib_MakeEdge(P1,P2);
54 DBRep::Set("distance",E);
55 return 0;
56}
762b6cec 57
7fd59977 58static Standard_Integer distmini(Draw_Interpretor& di, Standard_Integer n, const char** a)
59{
60 Standard_Integer i1;
61// gp_Pnt P;
62
63 if (n != 4) return 1;
64
65 const char *ns1 = (a[2]), *ns2 = (a[3]), *ns0 = (a[1]);
66 TopoDS_Shape S1(DBRep::Get(ns1)), S2(DBRep::Get(ns2)) ;
67 BRepExtrema_DistShapeShape dst(S1 ,S2 );
68
69
70 if (dst.IsDone())
71 {
72#ifdef DEB
73 //dst.Dump(cout);
74 Standard_SStream aSStream;
75 dst.Dump(aSStream);
76 di << aSStream;
77#endif
78
79 char named[100];
91322f44 80 Sprintf(named, "%s%s" ,ns0,"_val");
7fd59977 81 char* tempd = named;
82 Draw::Set(tempd,dst.Value());
83 di << named << " ";
84
85 for (i1=1; i1<= dst.NbSolution(); i1++)
86 {
87 gp_Pnt P1,P2;
88 P1 = (dst.PointOnShape1(i1));
89 P2 = (dst.PointOnShape2(i1));
90 if (dst.Value()<=1.e-9)
91 {
92 TopoDS_Vertex V =BRepLib_MakeVertex(P1);
93 char namev[100];
94 if (i1==1)
91322f44 95 Sprintf(namev, "%s" ,ns0);
96 else Sprintf(namev, "%s%d" ,ns0,i1);
7fd59977 97 char* tempv = namev;
98 DBRep::Set(tempv,V);
99 di << namev << " ";
100 }
101 else
102 {char name[100];
103 TopoDS_Edge E = BRepLib_MakeEdge (P1, P2);
104 if (i1==1)
91322f44 105 {Sprintf(name,"%s",ns0);}
106 else {Sprintf(name,"%s%d",ns0,i1);}
7fd59977 107 char* temp = name;
108 DBRep::Set(temp,E);
109 di << name << " " ;
110 }
111 }
112 }
113
114 else di << "probleme"<< "\n";
115 //else cout << "probleme"<< endl;
116 return 0;
117}
118
119//=======================================================================
120//function : ExtremaCommands
121//purpose :
122//=======================================================================
123
762b6cec 124void BRepTest::ExtremaCommands (Draw_Interpretor& theCommands)
7fd59977 125{
762b6cec 126 static const char* aGroup = "TOPOLOGY Extrema commands";
127 static Standard_Boolean isDone = Standard_False;
128 if (isDone)
129 {
130 return;
131 }
132 isDone = Standard_True;
133
134 theCommands.Add ("dist",
135 "dist Shape1 Shape2",
136 __FILE__,
137 distance,
138 aGroup);
139
140 theCommands.Add ("distmini",
141 "distmini name Shape1 Shape2",
142 __FILE__,
143 distmini,
144 aGroup);
7fd59977 145}