1 // Created on: 2000-08-22
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <ShapeProcess_ShapeContext.ixx>
18 #include <TCollection_AsciiString.hxx>
19 #include <TopoDS_Iterator.hxx>
20 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
21 #include <BRep_Builder.hxx>
23 #include <Message_Msg.hxx>
24 #include <Message_Messenger.hxx>
25 #include <Message_ListOfMsg.hxx>
26 #include <Message_ListIteratorOfListOfMsg.hxx>
27 #include <ShapeExtend_MsgRegistrator.hxx>
28 #include <ShapeExtend_DataMapOfShapeListOfMsg.hxx>
30 //=======================================================================
31 //function : ShapeProcess_ShapeContext
33 //=======================================================================
35 ShapeProcess_ShapeContext::ShapeProcess_ShapeContext (const Standard_CString file,
36 const Standard_CString seq)
37 : ShapeProcess_Context ( file, seq ), myUntil(TopAbs_FACE)
41 //=======================================================================
42 //function : ShapeProcess_ShapeContext
44 //=======================================================================
46 ShapeProcess_ShapeContext::ShapeProcess_ShapeContext (const TopoDS_Shape &S,
47 const Standard_CString file,
48 const Standard_CString seq)
49 : ShapeProcess_Context ( file, seq ), myUntil(TopAbs_FACE)
54 //=======================================================================
57 //=======================================================================
59 void ShapeProcess_ShapeContext::Init (const TopoDS_Shape &S)
62 myMsg = new ShapeExtend_MsgRegistrator;
64 myResult = myShape;//.Nullify();
67 //=======================================================================
70 //=======================================================================
72 const TopoDS_Shape &ShapeProcess_ShapeContext::Shape () const
77 //=======================================================================
80 //=======================================================================
82 const TopoDS_Shape &ShapeProcess_ShapeContext::Result () const
87 //=======================================================================
90 //=======================================================================
92 const TopTools_DataMapOfShapeShape &ShapeProcess_ShapeContext::Map () const
97 //=======================================================================
100 //=======================================================================
102 Handle(ShapeExtend_MsgRegistrator) &ShapeProcess_ShapeContext::Messages ()
107 //=======================================================================
108 //function : Messages
110 //=======================================================================
112 const Handle(ShapeExtend_MsgRegistrator) &ShapeProcess_ShapeContext::Messages () const
117 //=======================================================================
118 //function : SetDetalisation
120 //=======================================================================
122 void ShapeProcess_ShapeContext::SetDetalisation (const TopAbs_ShapeEnum level)
127 //=======================================================================
128 //function : GetDetalisation
130 //=======================================================================
132 TopAbs_ShapeEnum ShapeProcess_ShapeContext::GetDetalisation () const
137 //=======================================================================
138 //function : SetResult
140 //=======================================================================
142 void ShapeProcess_ShapeContext::SetResult (const TopoDS_Shape &res)
145 myMap.Bind ( myShape, myResult );
148 //=======================================================================
149 //function : RecordModification
151 //=======================================================================
155 static void DumpMap (const TopTools_DataMapOfShapeShape &map)
157 cout << "----" << endl;
158 cout << "Map:" << endl;
159 for (TopTools_DataMapIteratorOfDataMapOfShapeShape It (map); It.More(); It.Next()) {
160 TopoDS_Shape S0 = It.Key(), S = It.Value();
161 cout << S0.TShape()->DynamicType()->Name() << "\t" << *(void**)&S0.TShape() <<
162 " \t-> " << S.TShape()->DynamicType()->Name() << "\t" << *(void**)&S.TShape() << endl;
164 cout << "----" << endl;
169 static void RecModif (const TopoDS_Shape &S,
170 const TopTools_DataMapOfShapeShape &repl,
171 TopTools_DataMapOfShapeShape &map,
172 const TopAbs_ShapeEnum until)
175 //gka -modification to keep history for shape with location (OCC21617)
176 TopLoc_Location aShLoc = S.Location();
177 TopLoc_Location aNullLoc;
178 r.Location(aNullLoc);
180 if ( map.IsBound ( r ) )
182 if ( ! r.IsNull() ) {
183 TopoDS_Shape res = r;
185 if ( repl.IsBound ( r.Located(aShLoc) ) ) {
186 res = repl.Find ( r.Located(aShLoc) );
187 // it is supposed that map is created for r having FORWARD orientation
188 // hence, if it is reversed, result should be reversed too
189 // INTERNAL or EXTERNAL orientations are not allowed
190 if ( r.Orientation() != TopAbs_FORWARD )
194 // Treat special case: if S was split, r will be a compound of
195 // resulting shapes, each to be checked separately
196 // It is supposed that repl does not contain such splitting
197 else if ( r.ShapeType() < S.ShapeType() ) {
198 TopoDS_Shape result = r.EmptyCopied();
199 result.Orientation(TopAbs_FORWARD); // protect against INTERNAL or EXTERNAL shapes
200 Standard_Boolean modif = Standard_False;
202 for ( TopoDS_Iterator it(r,Standard_False); it.More(); it.Next() ) {
203 TopoDS_Shape sh = it.Value();
204 if ( repl.IsBound(sh) ) {
205 TopoDS_Shape newsh = repl.Find(sh);
206 if ( ! newsh.IsNull() ) B.Add ( result, newsh );
207 modif = Standard_True;
209 else B.Add ( result, sh );
211 if ( modif ) res = result;
214 if ( res != r ) map.Bind ( S.Located(aNullLoc), res );
217 if ( until == TopAbs_SHAPE || S.ShapeType() >= until ) return;
219 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
220 RecModif ( it.Value(), repl, map, until );
224 void ShapeProcess_ShapeContext::RecordModification (const TopTools_DataMapOfShapeShape &repl)
226 if ( repl.Extent() <=0 ) return;
227 RecModif ( myShape, repl, myMap, myUntil );
228 if ( myMap.IsBound(myShape) ) myResult = myMap.Find ( myShape );
230 // cout << "Modifier: " << endl; DumpMap (myMap);
234 //=======================================================================
235 //function : RecordModification
237 //=======================================================================
239 static void RecModif (const TopoDS_Shape &S,
240 const Handle(ShapeBuild_ReShape) &repl,
241 const Handle(ShapeExtend_MsgRegistrator) &msg,
242 TopTools_DataMapOfShapeShape &map,
243 Handle(ShapeExtend_MsgRegistrator) &myMsg,
244 const TopAbs_ShapeEnum until)
248 //gka -modification to keep history for shape with location (OCC21617)
249 TopLoc_Location aNullLoc;
250 TopoDS_Shape aS = S.Located(aNullLoc);
253 if ( map.IsBound ( r ) )
255 if ( ! r.IsNull() ) {
257 if ( repl->Status (r, res, Standard_True ) && res != r )
258 map.Bind ( aS, res );
260 // Treat special case: if S was split, r will be a compound of
261 // resulting shapes, recursive procedure should be applied
262 else if ( r.ShapeType() < S.ShapeType() ) {
263 res = repl->Apply ( r, (TopAbs_ShapeEnum)((Standard_Integer)S.ShapeType()+1) );
264 if ( res != r ) map.Bind ( aS, res );
268 // update messages (messages must be taken from each level in the substitution map)
269 if ( ! r.IsNull() && ! myMsg.IsNull() &&
270 ! msg.IsNull() && msg->MapShape().Extent() >0 ) {
271 TopoDS_Shape cur, next = r;
272 const ShapeExtend_DataMapOfShapeListOfMsg& msgmap = msg->MapShape();
275 if (msgmap.IsBound (cur)) {
276 const Message_ListOfMsg &msglist = msgmap.Find (cur);
277 for (Message_ListIteratorOfListOfMsg iter (msglist); iter.More(); iter.Next()) {
278 myMsg->Send ( S, iter.Value(), Message_Warning );
281 next = repl->Value (cur);
282 } while ( ! next.IsNull() && cur != next);
285 if ( until == TopAbs_SHAPE || S.ShapeType() >= until ) return;
287 for ( TopoDS_Iterator it(S,Standard_False,Standard_False); it.More(); it.Next() ) {
288 RecModif ( it.Value(), repl, msg, map, myMsg, until );
292 void ShapeProcess_ShapeContext::RecordModification (const Handle(ShapeBuild_ReShape) &repl,
293 const Handle(ShapeExtend_MsgRegistrator) &msg)
296 RecModif ( myShape, repl, msg, myMap, myMsg, myUntil );
297 if ( myMap.IsBound(myShape) )
299 myResult = myMap.Find ( myShape );
300 myResult.Location(myShape.Location());
303 // cout << "ReShape: " << endl; DumpMap (myMap);
307 //=======================================================================
308 //function : RecordModification
310 //=======================================================================
312 void ShapeProcess_ShapeContext::RecordModification (const Handle(ShapeBuild_ReShape) &repl)
314 Handle(ShapeExtend_MsgRegistrator) msg;
315 RecordModification ( repl, msg );
318 //=======================================================================
319 //function : AddMessage
321 //=======================================================================
323 void ShapeProcess_ShapeContext::AddMessage (const TopoDS_Shape &S,
324 const Message_Msg &msg,
325 const Message_Gravity grv)
327 if ( ! myMsg.IsNull() ) myMsg->Send ( S, msg, grv );
330 //=======================================================================
331 //function : RecordModification
333 //=======================================================================
335 static void ExplodeModifier (const TopoDS_Shape &S,
336 const BRepTools_Modifier &repl,
337 TopTools_DataMapOfShapeShape &map,
338 const TopAbs_ShapeEnum until)
340 TopoDS_Shape res = repl.ModifiedShape ( S );
346 if ( until == TopAbs_SHAPE || S.ShapeType() >= until ) return;
347 for ( TopoDS_Iterator it(S); it.More(); it.Next() ) {
348 ExplodeModifier ( it.Value(), repl, map, until );
352 void ShapeProcess_ShapeContext::RecordModification (const TopoDS_Shape &S,
353 const BRepTools_Modifier &repl)
355 TopTools_DataMapOfShapeShape map;
356 ExplodeModifier ( S, repl, map, myUntil );
357 RecordModification ( map );
360 //=======================================================================
361 //function : GetContinuity
363 //=======================================================================
365 Standard_Boolean ShapeProcess_ShapeContext::GetContinuity (const Standard_CString param,
366 GeomAbs_Shape &cont) const
368 TCollection_AsciiString str;
369 if ( ! GetString ( param, str ) ) return Standard_False;
375 if ( str.IsEqual ( "C0" ) ) cont = GeomAbs_C0;
376 else if ( str.IsEqual ( "G1" ) ) cont = GeomAbs_G1;
377 else if ( str.IsEqual ( "C1" ) ) cont = GeomAbs_C1;
378 else if ( str.IsEqual ( "G2" ) ) cont = GeomAbs_G2;
379 else if ( str.IsEqual ( "C2" ) ) cont = GeomAbs_C2;
380 else if ( str.IsEqual ( "C3" ) ) cont = GeomAbs_C3;
381 else if ( str.IsEqual ( "CN" ) ) cont = GeomAbs_CN;
382 else return Standard_False;
383 return Standard_True;
386 //=======================================================================
387 //function : ContinuityVal
389 //=======================================================================
391 GeomAbs_Shape ShapeProcess_ShapeContext::ContinuityVal (const Standard_CString param,
392 const GeomAbs_Shape def) const
395 return GetContinuity ( param, val ) ? val : def;
398 //=======================================================================
399 //function : PrintStatistics
401 //=======================================================================
403 void ShapeProcess_ShapeContext::PrintStatistics () const
405 Standard_Integer SS = 0, SN = 0, FF = 0, FS = 0, FN = 0;
406 for (TopTools_DataMapIteratorOfDataMapOfShapeShape It (myMap); It.More(); It.Next()) {
407 TopoDS_Shape keyshape = It.Key(), valueshape = It.Value();
408 if (keyshape.ShapeType() == TopAbs_SHELL)
409 if (valueshape.IsNull()) SN++;
411 else if (keyshape.ShapeType() == TopAbs_FACE)
413 if (valueshape.IsNull()) FN++;
414 else if (valueshape.ShapeType() == TopAbs_SHELL) FS++;
420 Message_Msg EPMSG100 ("PrResult.Print.MSG100"); //Mapping:
421 Messenger()->Send (EPMSG100, Message_Info);
422 Message_Msg TPMSG50 ("PrResult.Print.MSG50"); // Shells:
423 Messenger()->Send (TPMSG50, Message_Info);
424 Message_Msg EPMSG110 ("PrResult.Print.MSG110"); // Result is Shell : %d
426 Messenger()->Send (EPMSG110, Message_Info);
427 Message_Msg EPMSG150 ("PrResult.Print.MSG150"); // No Result : %d
429 Messenger()->Send (EPMSG150.Get(), Message_Info);
431 TCollection_AsciiString tmp110 (EPMSG110.Original()), tmp150 (EPMSG150.Original());
432 EPMSG110.Set (tmp110.ToCString());
433 EPMSG150.Set (tmp150.ToCString());
435 Message_Msg TPMSG55 ("PrResult.Print.MSG55"); // Faces:
436 Messenger()->Send (TPMSG55, Message_Info);
437 Message_Msg EPMSG115 ("PrResult.Print.MSG115"); // Result is Face : %d
439 Messenger()->Send (EPMSG115, Message_Info);
441 Messenger()->Send (EPMSG110, Message_Info);
443 Messenger()->Send (EPMSG150, Message_Info);
446 Standard_Real SPR = 1, FPR = 1;
447 Standard_Integer STotalR = SS, FTotalR = FF + FS;
448 Standard_Integer NbS = STotalR + SN, NbF = FTotalR + FN;
449 if (NbS > 0) SPR = 1. * (NbS - SN) / NbS;
450 if (NbF > 0) FPR = 1. * (NbF - FN) / NbF;
451 Message_Msg PMSG200 ("PrResult.Print.MSG200"); //Preparation ratio:
452 Messenger()->Send (PMSG200, Message_Info);
453 Message_Msg PMSG205 ("PrResult.Print.MSG205"); // Shells: %d per cent
454 PMSG205.Arg ((Standard_Integer) (100. * SPR));
455 Messenger()->Send (PMSG205, Message_Info);
456 Message_Msg PMSG210 ("PrResult.Print.MSG210"); // Faces : %d per cent
457 PMSG210.Arg ((Standard_Integer) (100. * FPR));
458 Messenger()->Send (PMSG210, Message_Info);