1 // Created on: 2021-04-27
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2021 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 <inspector/MessageView_ActionsTest.hxx>
18 #include <inspector/MessageModel_ItemReport.hxx>
19 #include <inspector/MessageModel_ItemRoot.hxx>
20 #include <inspector/MessageModel_ItemAlert.hxx>
21 #include <inspector/MessageModel_TreeModel.hxx>
22 #include <inspector/ViewControl_Tools.hxx>
24 #include <Message.hxx>
25 #include <Message_AlertExtended.hxx>
26 #include <Message_Level.hxx>
27 #include <Message_Messenger.hxx>
32 #include <Bnd_Box.hxx>
33 #include <Bnd_OBB.hxx>
34 #include <BRepBuilderAPI_MakeEdge.hxx>
35 #include <OSD_Chronometer.hxx>
36 #include <Quantity_Color.hxx>
37 #include <Quantity_ColorRGBA.hxx>
38 #include <TCollection_AsciiString.hxx>
39 #include <TopoDS_AlertAttribute.hxx>
41 #include <Standard_WarningsDisable.hxx>
43 #include <QFileDialog>
44 #include <QItemSelectionModel>
46 #include <QMessageBox>
48 #include <Standard_WarningsRestore.hxx>
52 // =======================================================================
53 // function : Constructor
55 // =======================================================================
56 MessageView_ActionsTest::MessageView_ActionsTest (QWidget* theParent,
57 MessageModel_TreeModel* theTreeModel, QItemSelectionModel* theModel)
58 : QObject (theParent), myTreeModel (theTreeModel), mySelectionModel (theModel)
60 myActions.insert (MessageModel_ActionType_TestMetric,
61 ViewControl_Tools::CreateAction ("Test <metric>", SLOT (OnTestMetric()), parent(), this));
62 myActions.insert (MessageModel_ActionType_TestMessenger,
63 ViewControl_Tools::CreateAction ("Test <Message_Messenger>", SLOT (OnTestMessenger()), parent(), this));
64 myActions.insert (MessageModel_ActionType_TestReportTree,
65 ViewControl_Tools::CreateAction ("Test <Tree of messages>", SLOT (OnTestReportTree()), parent(), this));
68 // =======================================================================
69 // function : AddMenuActions
71 // =======================================================================
72 void MessageView_ActionsTest::AddMenuActions (const QModelIndexList& theSelectedIndices, QMenu* theMenu)
74 MessageModel_ItemReportPtr aReportItem;
75 for (QModelIndexList::const_iterator aSelIt = theSelectedIndices.begin(); aSelIt != theSelectedIndices.end(); aSelIt++)
77 QModelIndex anIndex = *aSelIt;
78 if (anIndex.column() != 0)
81 TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
85 MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (anItemBase);
89 aReportItem = itemDynamicCast<MessageModel_ItemReport> (anItemBase);
93 MessageModel_ItemAlertPtr anAlertItem = itemDynamicCast<MessageModel_ItemAlert> (anItemBase);
98 if (aReportItem && !aReportItem->GetReport().IsNull())
100 theMenu->addAction (myActions[MessageModel_ActionType_TestMetric]);
101 theMenu->addAction (myActions[MessageModel_ActionType_TestMessenger]);
102 theMenu->addAction (myActions[MessageModel_ActionType_TestReportTree]);
104 bool isReportEnabled = aReportItem->GetReport()->IsActiveInMessenger();
105 myActions[MessageModel_ActionType_TestMetric]->setEnabled (isReportEnabled);
106 myActions[MessageModel_ActionType_TestMessenger]->setEnabled (isReportEnabled);
107 myActions[MessageModel_ActionType_TestReportTree]->setEnabled (isReportEnabled);
109 theMenu->addSeparator();
112 // =======================================================================
113 // function : getSelectedReport
115 // =======================================================================
116 Handle(Message_Report) MessageView_ActionsTest::getSelectedReport (QModelIndex& theReportIndex) const
118 MessageModel_ItemReportPtr aReportItem;
119 QModelIndexList aSelectedIndices = mySelectionModel->selectedIndexes();
120 for (QModelIndexList::const_iterator aSelIt = aSelectedIndices.begin(); aSelIt != aSelectedIndices.end(); aSelIt++)
122 QModelIndex anIndex = *aSelIt;
123 if (anIndex.column() != 0)
126 TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex);
130 aReportItem = itemDynamicCast<MessageModel_ItemReport> (anItemBase);
131 theReportIndex = anIndex;
138 return aReportItem->GetReport();
141 // =======================================================================
142 // function : OnTestMetric
144 // =======================================================================
145 void MessageView_ActionsTest::OnTestMetric()
147 QModelIndex aReportIndex;
148 Handle(Message_Report) aReport = getSelectedReport (aReportIndex);
149 if (aReport.IsNull())
152 OCCT_ADD_MESSAGE_LEVEL_SENTRY ("MessageModel_Actions::OnTestMetric()");
153 clock_t start_time = clock();
155 Standard_Integer aCounter = 1500;
156 Standard_Real aValue = 0., aValue2 = 0.1;
158 for (int aTopIt = 0; aTopIt < 4; aTopIt++)
160 Message::SendInfo() << "Calculate";
161 for (int j = 0; j < aCounter; j++)
163 for (int i = 0; i < aCounter; i++)
165 aValue = (aValue * 2. + 3.) * 0.5 - 0.3 * 0.5;
167 Standard_Real aValue3 = aValue + aValue2 * 0.2;
173 myTreeModel->UpdateTreeModel();
175 clock_t end_time = clock();
176 std::cout << "clock() = " << end_time - start_time << std::endl;
179 // =======================================================================
180 // function : createShapeOnLevel
182 // =======================================================================
183 void createShapeOnLevel()
185 OCCT_ADD_MESSAGE_LEVEL_SENTRY ("createShapeOnLevel")
187 Message_Messenger::StreamBuffer sout = Message::SendInfo();
189 BRepBuilderAPI_MakeEdge aBuilder (gp_Pnt (0., 0., 0.), gp_Pnt (20., 10., 20.));
190 TopoDS_Shape aShape = aBuilder.Shape();
192 Message::DefaultMessenger() << aShape;
195 // =======================================================================
196 // function : createShape
198 // =======================================================================
201 Message_Messenger::StreamBuffer sout = Message::SendInfo();
202 BRepBuilderAPI_MakeEdge aBuilder (gp_Pnt (0., 0., 0.), gp_Pnt (20., 10., 20.));
203 TopoDS_Shape aShape = aBuilder.Shape();
205 Message::DefaultMessenger() << aShape;
206 createShapeOnLevel();
209 // =======================================================================
210 // function : OnTestMessenger
212 // =======================================================================
213 void MessageView_ActionsTest::OnTestMessenger()
216 OCCT_ADD_MESSAGE_LEVEL_SENTRY ("MessageModel_Actions::OnTestMessenger()")
218 Message::DefaultMessenger()->Send ("Values");
219 Message::DefaultMessenger()->Send ("Values second");
221 Message_Messenger::StreamBuffer sout = Message::SendInfo();
224 gp_XYZ aCoords (1.3, 2.3, 3.4);
225 aCoords.DumpJson (sout);
226 sout.Flush(Standard_True);
230 gp_Dir aDir (0.3, 0.3, 0.4);
231 aDir.DumpJson (sout);
232 sout.Flush(Standard_True);
236 gp_Ax1 aCoords (gp_Pnt (1.3, 2.3, 3.4), gp_Dir (0.3, 0.3, 0.4));
237 aCoords.DumpJson (sout);
238 sout.Flush(Standard_True);
242 gp_Ax2 aCoords (gp_Pnt (10.3, 20.3, 30.4), gp_Dir (0.3, 0.3, 0.4));
243 aCoords.DumpJson (sout);
244 sout.Flush(Standard_True);
248 gp_Ax3 aPln (gp_Pnt (10., 20., 15.), gp_Dir (0., 0., 1.), gp_Dir (1., 0., 0.));
249 aPln.DumpJson (sout);
250 sout.Flush(Standard_True);
255 aTrsf.SetRotation (gp::OZ(), 0.3);
256 aTrsf.SetTranslationPart (gp_Vec (15., 15., 15.));
257 aTrsf.SetScaleFactor (3.);
259 aTrsf.DumpJson (sout);
260 sout.Flush(Standard_True);
264 Bnd_Box aBox (gp_Pnt (20., 15., 10.), gp_Pnt (25., 20., 15.));
265 aBox.DumpJson (sout);
266 sout.Flush (Standard_True);
270 Bnd_OBB anOBB (gp_Pnt (-10., -15., -10.), gp_Dir (1., 0., 0.), gp_Dir (0., 1., 0.), gp_Dir (0., 0., 1.),
272 anOBB.DumpJson (sout);
273 sout.Flush (Standard_True);
275 // Quantity_ColorRGBA
277 Quantity_ColorRGBA aColor (0.2f, 0.8f, 0.8f, 0.2f);
278 aColor.DumpJson (sout);
279 sout.Flush (Standard_True);
283 Quantity_Color aColor (0.8, 0.8, 0.8, Quantity_TOC_RGB);
284 aColor.DumpJson (sout);
285 sout.Flush (Standard_True);
291 myTreeModel->UpdateTreeModel();
294 // =======================================================================
295 // function : levelAlerts
297 // =======================================================================
298 void levelAlerts (const int theCurrentLevel, const int theTopLevel)
300 if (theTopLevel - theCurrentLevel <= 0)
303 OCCT_ADD_MESSAGE_LEVEL_SENTRY (TCollection_AsciiString ("Level: " ) + theCurrentLevel)
305 Message_Messenger::StreamBuffer sout = Message::SendInfo();
306 sout << "Alert(" << theCurrentLevel << "): " << 1 << ", " << 2 << std::endl;
307 sout << "Alert(" << theCurrentLevel << "): " << 3 << ", " << 4 << std::endl;
309 levelAlerts (theCurrentLevel + 1, theTopLevel);
311 sout << "Alert(" << theCurrentLevel << "): " << 4 << ", " << 5 << std::endl;
314 // =======================================================================
315 // function : levelAlert
317 // =======================================================================
318 void levelAlert (const int theCurrentLevel, const int theTopLevel)
320 if (theTopLevel - theCurrentLevel <= 0)
323 OCCT_ADD_MESSAGE_LEVEL_SENTRY ("levelAlert")
325 Message_Messenger::StreamBuffer sout = Message::SendInfo();
326 sout << "Level: " << theCurrentLevel << "(Single, no alerts on the level)" << std::endl;
328 levelAlerts (theCurrentLevel + 1, theTopLevel);
331 // =======================================================================
332 // function : OnTestReportTree
334 // =======================================================================
335 void MessageView_ActionsTest::OnTestReportTree()
337 OCCT_ADD_MESSAGE_LEVEL_SENTRY ("MessageModel_Actions::OnTestReportTree()")
338 Message_Messenger::StreamBuffer sout = Message::SendInfo();
341 levelAlerts (1, aTopLevel);
343 sout << "Alert: " << 4 << std::endl;
344 levelAlert (1, aTopLevel);
346 myTreeModel->UpdateTreeModel();