0028786: Refactoring of the Warning/Error reporting system of Boolean Operations...
[occt.git] / src / BOPTest / BOPTest.cxx
CommitLineData
b311480e 1// Created on: 2000-05-18
2// Created by: Peter KURNEV
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
42cf5bc1 16
17#include <BOPTest.hxx>
18#include <BRepTest.hxx>
7fd59977 19#include <DBRep.hxx>
20#include <Draw_Interpretor.hxx>
7868210d 21#include <Draw_PluginMacro.hxx>
7fd59977 22#include <GeometryTest.hxx>
42cf5bc1 23#include <GeomliteTest.hxx>
7fd59977 24#include <HLRTest.hxx>
33ba8565 25#include <NCollection_Map.hxx>
42cf5bc1 26#include <MeshTest.hxx>
33ba8565 27#include <Message.hxx>
28#include <Message_Msg.hxx>
29#include <Message_Messenger.hxx>
7868210d 30#include <SWDRAW.hxx>
33ba8565 31#include <TopoDS_AlertWithShape.hxx>
32
33#include <BOPAlgo_Algo.hxx>
34#include <BOPTest_Objects.hxx>
7fd59977 35
36//=======================================================================
37//function : AllCommands
38//purpose :
39//=======================================================================
b311480e 40void BOPTest::AllCommands(Draw_Interpretor& theCommands)
7fd59977 41{
42 static Standard_Boolean done = Standard_False;
43 if (done) return;
7fd59977 44 done = Standard_True;
4e57c75e 45 //
46 BOPTest::BOPCommands (theCommands);
47 BOPTest::CheckCommands (theCommands);
48 BOPTest::LowCommands (theCommands);
49 BOPTest::TolerCommands (theCommands);
50 BOPTest::ObjCommands (theCommands);
51 BOPTest::PartitionCommands (theCommands);
a493b4a1 52 BOPTest::APICommands (theCommands);
53 BOPTest::OptionCommands (theCommands);
54 BOPTest::HistoryCommands (theCommands);
b1682e23 55 BOPTest::DebugCommands (theCommands);
338434c7 56 BOPTest::CellsCommands (theCommands);
6ca1c746 57 BOPTest::UtilityCommands (theCommands);
7fd59977 58}
4e57c75e 59//=======================================================================
60//function : Factory
61//purpose :
62//=======================================================================
63 void BOPTest::Factory(Draw_Interpretor& theCommands)
7fd59977 64{
65 static Standard_Boolean FactoryDone = Standard_False;
66 if (FactoryDone) return;
67
68 FactoryDone = Standard_True;
7fd59977 69
4e57c75e 70 DBRep::BasicCommands(theCommands);
71 GeomliteTest::AllCommands(theCommands);
72 GeometryTest::AllCommands(theCommands);
73 BRepTest::AllCommands(theCommands);
74 MeshTest::Commands(theCommands);
4e57c75e 75 HLRTest::Commands(theCommands);
76 BOPTest::AllCommands(theCommands);
7868210d 77 SWDRAW::Init (theCommands);
7fd59977 78}
7868210d 79// Declare entry point PLUGINFACTORY
80DPLUGIN(BOPTest)
33ba8565 81
82//=======================================================================
83//function : ReportAlerts
84//purpose :
85//=======================================================================
86
87void BOPTest::ReportAlerts (const BOPAlgo_Algo& theAlgorithm)
88{
89 // first report warnings, then errors
90 Message_Gravity anAlertTypes[2] = { Message_Warning, Message_Fail };
91 for (int iGravity = 0; iGravity < 2; iGravity++)
92 {
93 // report shapes for the same type of alert together
94 NCollection_Map<Handle(Standard_Transient)> aPassedTypes;
95 const Message_ListOfAlert& aList = theAlgorithm.GetReport()->GetAlerts (anAlertTypes[iGravity]);
96 for (Message_ListOfAlert::Iterator aIt (aList); aIt.More(); aIt.Next())
97 {
98 // check that this type of warnings has not yet been processed
99 if (! aPassedTypes.Add (aIt.Value()->DynamicType()))
100 continue;
101
102 // get alert message
103 Message_Msg aMsg (aIt.Value()->GetMessageKey());
104 TCollection_ExtendedString aText = aMsg.Get();
105
106 // collect all shapes if any attached to this alert
107 if (BOPTest_Objects::DrawWarnShapes())
108 {
109 TCollection_AsciiString aShapeList;
110 Standard_Integer aNbShapes = 0;
111 for (Message_ListOfAlert::Iterator aIt2 (aIt); aIt2.More(); aIt2.Next())
112 {
113 Handle(TopoDS_AlertWithShape) aShapeAlert = Handle(TopoDS_AlertWithShape)::DownCast (aIt2.Value());
114
115 if (! aShapeAlert.IsNull() && ! aShapeAlert->GetShape().IsNull())
116 {
117 //
118 char aName[80];
119 Sprintf(aName, "%ss_%d_%d", (iGravity ? "e" : "w"), aPassedTypes.Extent(), ++aNbShapes);
120 DBRep::Set(aName, aShapeAlert->GetShape());
121 //
122 aShapeList += " ";
123 aShapeList += aName;
124 }
125 }
126 aText += (aNbShapes ? ": " : "(no shapes attached)");
127 aText += aShapeList;
128 }
129
130 // output message with list of shapes
131 Message::DefaultMessenger()->Send (aText, anAlertTypes[iGravity]);
132 }
133 }
134}