0030206: Improve API of commands bbop and bapibop
[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.hxx>
21 #include <Draw_Interpretor.hxx>
22 #include <Draw_PluginMacro.hxx>
23 #include <GeometryTest.hxx>
24 #include <GeomliteTest.hxx>
25 #include <HLRTest.hxx>
26 #include <NCollection_Map.hxx>
27 #include <MeshTest.hxx>
28 #include <Message.hxx>
29 #include <Message_Alert.hxx>
30 #include <Message_Msg.hxx>
31 #include <Message_Messenger.hxx>
32 #include <Message_Report.hxx>
33 #include <SWDRAW.hxx>
34 #include <TopoDS_AlertWithShape.hxx>
35
36 #include <BOPAlgo_Alerts.hxx>
37 #include <BOPTest_Objects.hxx>
38
39 //=======================================================================
40 //function : AllCommands
41 //purpose  : 
42 //=======================================================================
43 void  BOPTest::AllCommands(Draw_Interpretor& theCommands)
44 {
45   static Standard_Boolean done = Standard_False;
46   if (done) return;
47   done = Standard_True;
48   //
49   BOPTest::BOPCommands       (theCommands);
50   BOPTest::CheckCommands     (theCommands);
51   BOPTest::LowCommands       (theCommands);
52   BOPTest::TolerCommands     (theCommands);
53   BOPTest::ObjCommands       (theCommands);
54   BOPTest::PartitionCommands (theCommands);
55   BOPTest::APICommands       (theCommands);
56   BOPTest::OptionCommands    (theCommands);
57   BOPTest::DebugCommands     (theCommands);
58   BOPTest::CellsCommands     (theCommands);
59   BOPTest::UtilityCommands   (theCommands);
60   BOPTest::RemoveFeaturesCommands(theCommands);
61   BOPTest::PeriodicityCommands(theCommands);
62   BOPTest::MkConnectedCommands(theCommands);
63 }
64 //=======================================================================
65 //function : Factory
66 //purpose  : 
67 //=======================================================================
68   void BOPTest::Factory(Draw_Interpretor& theCommands)
69 {
70   static Standard_Boolean FactoryDone = Standard_False;
71   if (FactoryDone) return;
72
73   FactoryDone = Standard_True;
74
75   DBRep::BasicCommands(theCommands);
76   GeomliteTest::AllCommands(theCommands);
77   GeometryTest::AllCommands(theCommands);
78   BRepTest::AllCommands(theCommands);
79   MeshTest::Commands(theCommands);
80   HLRTest::Commands(theCommands);
81   BOPTest::AllCommands(theCommands);
82   SWDRAW::Init (theCommands);
83 }
84 // Declare entry point PLUGINFACTORY
85 DPLUGIN(BOPTest)
86
87 //=======================================================================
88 //function : ReportAlerts
89 //purpose  : 
90 //=======================================================================
91
92 void BOPTest::ReportAlerts(const Handle(Message_Report)& theReport)
93 {
94   // first report warnings, then errors
95   Message_Gravity anAlertTypes[2] = { Message_Warning, Message_Fail };
96   TCollection_ExtendedString aMsgType[2] = { "Warning: ", "Error: " };
97   for (int iGravity = 0; iGravity < 2; iGravity++)
98   {
99     // report shapes for the same type of alert together
100     NCollection_Map<Handle(Standard_Transient)> aPassedTypes;
101     const Message_ListOfAlert& aList = theReport->GetAlerts (anAlertTypes[iGravity]);
102     for (Message_ListOfAlert::Iterator aIt (aList); aIt.More(); aIt.Next())
103     {
104       // check that this type of warnings has not yet been processed
105       const Handle(Standard_Type)& aType = aIt.Value()->DynamicType();
106       if (!aPassedTypes.Add(aType))
107         continue;
108
109       // get alert message
110       Message_Msg aMsg (aIt.Value()->GetMessageKey());
111       TCollection_ExtendedString aText = aMsgType[iGravity] + aMsg.Get();
112
113       // collect all shapes if any attached to this alert
114       if (BOPTest_Objects::DrawWarnShapes())
115       {
116         TCollection_AsciiString aShapeList;
117         Standard_Integer aNbShapes = 0;
118         for (Message_ListOfAlert::Iterator aIt2 (aIt); aIt2.More(); aIt2.Next())
119         {
120           Handle(TopoDS_AlertWithShape) aShapeAlert = Handle(TopoDS_AlertWithShape)::DownCast (aIt2.Value());
121
122           if (!aShapeAlert.IsNull() &&
123               (aType == aShapeAlert->DynamicType()) &&
124               !aShapeAlert->GetShape().IsNull())
125           {
126             //
127             char aName[80];
128             Sprintf(aName, "%ss_%d_%d", (iGravity ? "e" : "w"), aPassedTypes.Extent(), ++aNbShapes);
129             DBRep::Set(aName, aShapeAlert->GetShape());
130             //
131             aShapeList += " ";
132             aShapeList += aName;
133           }
134         }
135         aText += (aNbShapes ? ": " : "(no shapes attached)");
136         aText += aShapeList;
137       }
138
139       // output message with list of shapes
140       Draw_Interpretor& aDrawInterpretor = Draw::GetInterpretor();
141       aDrawInterpretor << aText << "\n";
142     }
143   }
144 }
145
146 //=======================================================================
147 //function : GetOperationType
148 //purpose  : 
149 //=======================================================================
150 BOPAlgo_Operation BOPTest::GetOperationType(const Standard_CString theOp)
151 {
152   TCollection_AsciiString anOp(theOp);
153   anOp.LowerCase();
154
155   if (anOp.IsIntegerValue())
156   {
157     // Check if the given value satisfies the enumeration.
158     Standard_Integer iOp = anOp.IntegerValue();
159     if (iOp >= 0 && iOp <= 4)
160     {
161       return static_cast<BOPAlgo_Operation>(iOp);
162     }
163     return BOPAlgo_UNKNOWN;
164   }
165
166   // Check for the meaningful symbolic operation parameter
167   if (anOp == "common")
168   {
169     return BOPAlgo_COMMON;
170   }
171   else if (anOp == "fuse")
172   {
173     return BOPAlgo_FUSE;
174   }
175   else if (anOp == "cut")
176   {
177     return BOPAlgo_CUT;
178   }
179   else if (anOp == "tuc" || anOp == "cut21")
180   {
181     return BOPAlgo_CUT21;
182   }
183   else if (anOp == "section")
184   {
185     return BOPAlgo_SECTION;
186   }
187
188   return BOPAlgo_UNKNOWN;
189 }