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