0030697: Draw Harness - Draw_Printer should not be set to Message::DefaultMessenger... IR-2019-11-22
authormzernova <mzernova@opencascade.com>
Mon, 6 May 2019 20:05:13 +0000 (23:05 +0300)
committerbugmaster <bugmaster@opencascade.com>
Sat, 23 Nov 2019 13:09:07 +0000 (16:09 +0300)
Fixed bugs that occurred when using the default std::cout from Message::DefaultMessenger() instead of Draw_Printer

A dedicated option was added to Draw_ProgressIndicator, for outputting data to the tcl when performing tests

Added -tclOutput parameter to XProgress command

13 files changed:
src/BOPTest/BOPTest.cxx
src/DBRep/DBRep.cxx
src/Draw/Draw_Commands.cxx
src/Draw/Draw_ProgressIndicator.cxx
src/Draw/Draw_ProgressIndicator.hxx
src/QABugs/QABugs_11.cxx
src/QABugs/QABugs_19.cxx
src/XSDRAW/XSDRAW.cxx
tests/bugs/modalg_5/bug22747
tests/bugs/moddata_2/bug22572
tests/bugs/moddata_2/bug22746_1
tests/bugs/moddata_2/bug22746_2
tests/bugs/moddata_2/bug22746_3

index 1f797ec..23c67bd 100644 (file)
@@ -17,6 +17,7 @@
 #include <BOPTest.hxx>
 #include <BRepTest.hxx>
 #include <DBRep.hxx>
+#include <Draw.hxx>
 #include <Draw_Interpretor.hxx>
 #include <Draw_PluginMacro.hxx>
 #include <GeometryTest.hxx>
@@ -136,7 +137,8 @@ void BOPTest::ReportAlerts(const Handle(Message_Report)& theReport)
       }
 
       // output message with list of shapes
-      Message::DefaultMessenger()->Send (aText, anAlertTypes[iGravity]);
+      Draw_Interpretor& aDrawInterpretor = Draw::GetInterpretor();
+      aDrawInterpretor << aText << "\n";
     }
   }
 }
index 0641003..f5d8ad9 100644 (file)
@@ -1332,13 +1332,23 @@ TopoDS_Shape DBRep::getShape (Standard_CString& theName,
 
 static Standard_Integer XProgress (Draw_Interpretor& di, Standard_Integer argc, const char **argv)
 {
-  for ( Standard_Integer i=1; i < argc; i++ ) {
+  for ( Standard_Integer i=1; i < argc; i++ )
+  {
     Standard_Boolean turn = Standard_True;
     if ( argv[i][0] == '-' ) turn = Standard_False;
     else if ( argv[i][0] != '+' ) continue;
-    if ( argv[i][1] == 't' ) Draw_ProgressIndicator::DefaultTextMode() = turn;
+
+    TCollection_AsciiString anArgCase (argv[i]);
+    anArgCase.LowerCase();
+    if (anArgCase == "-tcloutput")
+    {
+      Draw_ProgressIndicator::DefaultTclOutput() = Standard_True;
+      return 0;
+    }
+    else if ( argv[i][1] == 't' ) Draw_ProgressIndicator::DefaultTextMode() = turn;
     else if ( argv[i][1] == 'g' ) Draw_ProgressIndicator::DefaultGraphMode() = turn;
-    else if ( ! strcmp ( argv[i], "-stop" ) && i+1 < argc ) {
+    else if ( ! strcmp ( argv[i], "-stop" ) && i+1 < argc )
+    {
       Standard_Address aPtr = 0;
       if (sscanf (argv[++i], "%p", &aPtr) == 1)
         Draw_ProgressIndicator::StopIndicator() = aPtr;
@@ -1463,7 +1473,13 @@ void  DBRep::BasicCommands(Draw_Interpretor& theCommands)
                  __FILE__,purgemmgt,g);
   
   // Add command for DRAW-specific ProgressIndicator
-  theCommands.Add ( "XProgress","XProgress [+|-t] [+|-g]: switch on/off textual and graphical mode of Progress Indicator",XProgress,"DE: General");
+  theCommands.Add ( "XProgress",
+                    "XProgress [+|-t] [+|-g] [-tclOutput]"
+                    "\n\t\t: The options are:"
+                    "\n\t\t:   +|-t, +|-g :  switch on/off textual and graphical mode of Progress Indicator"
+                    "\n\t\t:   -tclOutput :  switch on data output mode in tcl"
+                    "\n\t\t: Allows to control the output form of Progress Indicator",
+                    XProgress,"DE: General");
 
   theCommands.Add("binsave", "binsave shape filename\n"
                   "\t\tsave the shape in the binary format file",
index 6444f5d..c375f9e 100644 (file)
 
 #include <Draw.hxx>
 #include <Draw_Drawable3D.hxx>
-#include <Draw_Printer.hxx>
 #include <Draw_ProgressIndicator.hxx>
-#include <Message.hxx>
-#include <Message_Messenger.hxx>
-#include <Message_PrinterOStream.hxx>
 #include <TCollection_AsciiString.hxx>
 
 void Draw::Commands (Draw_Interpretor& theCommands)
 {
-  static Standard_Boolean isFirstTime = Standard_True;
-  if (isFirstTime)
-  {
-    // override default std::cout printer by draw interpretor printer
-    const Handle(Message_Messenger)& aMsgMgr = Message::DefaultMessenger();
-    if (!aMsgMgr.IsNull())
-    {
-      aMsgMgr->RemovePrinters (STANDARD_TYPE (Message_PrinterOStream));
-      aMsgMgr->RemovePrinters (STANDARD_TYPE (Draw_Printer));
-      aMsgMgr->AddPrinter (new Draw_Printer (theCommands));
-    }
-    isFirstTime = Standard_False;
-  }
-
   Draw::BasicCommands(theCommands);
   Draw::VariableCommands(theCommands);
   Draw::GraphicCommands(theCommands);
index 8c68e7e..6c92b2d 100644 (file)
@@ -31,7 +31,8 @@ IMPLEMENT_STANDARD_RTTIEXT(Draw_ProgressIndicator,Message_ProgressIndicator)
 Draw_ProgressIndicator::Draw_ProgressIndicator (const Draw_Interpretor &di, Standard_Real theUpdateThreshold)
 : myTextMode ( DefaultTextMode() ),
   myGraphMode ( DefaultGraphMode() ),
-  myDraw ( (Standard_Address)&di ),
+  myTclOutput ( DefaultTclOutput() ),
+  myDraw ( (Draw_Interpretor*)&di ),
   myShown ( Standard_False ),
   myBreak ( Standard_False ),
   myUpdateThreshold ( 0.01 * theUpdateThreshold ),
@@ -59,7 +60,7 @@ void Draw_ProgressIndicator::Reset()
 {
   Message_ProgressIndicator::Reset();
   if ( myShown ) {
-    ((Draw_Interpretor*)myDraw)->Eval ( "destroy .xprogress" );
+    myDraw->Eval ( "destroy .xprogress" );
     myShown = Standard_False;
   }
   myBreak = Standard_False;
@@ -145,7 +146,7 @@ Standard_Boolean Draw_ProgressIndicator::Show(const Standard_Boolean force)
                          "message .xprogress.text -width 400 -text \"Progress 0%%\";"
                          "button .xprogress.stop -text \"Break\" -relief groove -width 9 -command {XProgress -stop %p};"
                          "pack .xprogress.bar .xprogress.text .xprogress.stop -side top;", this );
-      ((Draw_Interpretor*)myDraw)->Eval ( command );
+      myDraw->Eval ( command );
       myShown = Standard_True;
     }
     std::stringstream aCommand;
@@ -155,16 +156,24 @@ Standard_Boolean Draw_ProgressIndicator::Show(const Standard_Boolean force)
     aCommand << ".xprogress.bar coords progress_next 2 2 " << (1 + 400 * GetScope(1).GetLast()) << " 21;";
     aCommand << ".xprogress.text configure -text \"" << aText.str() << "\";";
     aCommand << "update";
-    ((Draw_Interpretor*)myDraw)->Eval (aCommand.str().c_str());
+    myDraw->Eval (aCommand.str().c_str());
   }
 
   // Print textual progress info
-  if ( myTextMode )
-    Message::DefaultMessenger()->Send (aText.str().c_str(), Message_Info);
-  
+  if (myTextMode)
+  {
+    if (myTclOutput && myDraw)
+    {
+      *myDraw << aText.str().c_str() << "\n";
+    }
+    else
+    {
+      std::cout << aText.str().c_str() << "\n";
+    }
+  }
   return Standard_True;
 }
-       
+
 //=======================================================================
 //function : UserBreak
 //purpose  : 
@@ -175,7 +184,7 @@ Standard_Boolean Draw_ProgressIndicator::UserBreak()
   if ( StopIndicator() == this ) {
 //    std::cout << "Progress Indicator - User Break: " << StopIndicator() << ", " << (void*)this << std::endl;
     myBreak = Standard_True;
-    ((Draw_Interpretor*)myDraw)->Eval ( "XProgress -stop 0" );
+    myDraw->Eval ( "XProgress -stop 0" );
   }
   return myBreak;
 }
@@ -225,29 +234,40 @@ Standard_Boolean Draw_ProgressIndicator::GetGraphMode() const
 //purpose  : 
 //=======================================================================
 
-Standard_Boolean &Draw_ProgressIndicator::DefaultTextMode () 
+Standard_Boolean &Draw_ProgressIndicator::DefaultTextMode()
 {
   static Standard_Boolean defTextMode = Standard_False;
   return defTextMode;
 }
-    
+
 //=======================================================================
 //function : DefaultGraphMode
 //purpose  : 
 //=======================================================================
 
-Standard_Boolean &Draw_ProgressIndicator::DefaultGraphMode () 
+Standard_Boolean &Draw_ProgressIndicator::DefaultGraphMode()
 {
   static Standard_Boolean defGraphMode = Standard_False;
   return defGraphMode;
 }
-    
+
+//=======================================================================
+//function : DefaultTclOutput
+//purpose  :
+//=======================================================================
+
+Standard_Boolean &Draw_ProgressIndicator::DefaultTclOutput()
+{
+  static Standard_Boolean defTclOutput = Standard_False;
+  return defTclOutput;
+}
+
 //=======================================================================
 //function : StopIndicator
 //purpose  : 
 //=======================================================================
 
-Standard_Address &Draw_ProgressIndicator::StopIndicator ()
+Standard_Address &Draw_ProgressIndicator::StopIndicator()
 {
   static Standard_Address stopIndicator = 0;
   return stopIndicator;
index bfb6710..0bfcfdb 100644 (file)
@@ -54,7 +54,13 @@ public:
   
   //! Gets graphical output mode (on/off)
   Standard_EXPORT Standard_Boolean GetGraphMode() const;
-  
+
+  //! Sets tcl output mode (on/off)
+  void SetTclOutput (const Standard_Boolean theTclOutput) { myTclOutput = theTclOutput; }
+
+  //! Gets tcl output mode (on/off)
+  Standard_Boolean GetTclOutput() const { return myTclOutput; }
+
   //! Clears/erases opened TCL windows if any
   //! and sets myBreak to False
   Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
@@ -69,7 +75,10 @@ public:
   
   //! Get/Set default values for output modes
   Standard_EXPORT static Standard_Boolean& DefaultGraphMode();
-  
+
+  //! Get/Set default values for tcl output mode
+  Standard_EXPORT static Standard_Boolean& DefaultTclOutput();
+
   //! Internal method for implementation of UserBreak mechanism;
   //! note that it uses static variable and thus not thread-safe! 
   Standard_EXPORT static Standard_Address& StopIndicator();
@@ -79,7 +88,8 @@ public:
 private:
   Standard_Boolean myTextMode;
   Standard_Boolean myGraphMode;
-  Standard_Address myDraw;
+  Standard_Boolean myTclOutput;
+  Draw_Interpretor* myDraw;
   Standard_Boolean myShown;
   Standard_Boolean myBreak;
   Standard_Real myUpdateThreshold;
index c7012e8..dff3a55 100644 (file)
@@ -4753,6 +4753,7 @@ Standard_Integer OCC28478 (Draw_Interpretor& di, Standard_Integer argc, const ch
   // test behavior of progress indicator when using nested scopes with names set by Sentry objects
   Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1);
   aProgress->SetTextMode (Standard_True);
+  aProgress->SetTclOutput (Standard_True);
 
   // Outer cycle
   Message_ProgressSentry anOuter (aProgress, "Outer", 0, nbOuter, 1);
index d61fcc5..b87dfa1 100644 (file)
@@ -23,6 +23,7 @@
 #include <BRepPrimAPI_MakeSphere.hxx>
 #include <DBRep.hxx>
 #include <Draw_Interpretor.hxx>
+#include <Draw_Printer.hxx>
 #include <DrawTrSurf.hxx>
 #include <GCE2d_MakeSegment.hxx>
 #include <Geom2d_TrimmedCurve.hxx>
@@ -33,6 +34,9 @@
 #include <gp_Quaternion.hxx>
 #include <Image_Color.hxx>
 #include <Image_PixMap.hxx>
+#include <Message.hxx>
+#include <Message_Messenger.hxx>
+#include <Message_PrinterOStream.hxx>
 #include <NCollection_Handle.hxx>
 #include <NCollection_IncAllocator.hxx>
 #include <NCollection_Map.hxx>
@@ -1702,7 +1706,16 @@ static Standard_Integer OCC23951 (Draw_Interpretor& di, Standard_Integer argc, c
     return 1;
   }
 
-  writer.Write(argv[1]);
+  const Handle(Message_Messenger)& aMsgMgr = Message::DefaultMessenger();
+  Message_SequenceOfPrinters aPrinters;
+  aPrinters.Append (aMsgMgr->ChangePrinters());
+  aMsgMgr->AddPrinter (new Draw_Printer (di));
+
+  writer.Write (argv[1]);
+
+  aMsgMgr->RemovePrinters (STANDARD_TYPE(Draw_Printer));
+  aMsgMgr->ChangePrinters().Append (aPrinters);
+
   return 0;
 }
 
@@ -1745,7 +1758,16 @@ static Standard_Integer OCC23950 (Draw_Interpretor& di, Standard_Integer argc, c
     return 1;
   }
 
+  const Handle(Message_Messenger)& aMsgMgr = Message::DefaultMessenger();
+  Message_SequenceOfPrinters aPrinters;
+  aPrinters.Append (aMsgMgr->ChangePrinters());
+  aMsgMgr->AddPrinter (new Draw_Printer (di));
+
   writer.Write (argv[1]);
+
+  aMsgMgr->RemovePrinters (STANDARD_TYPE(Draw_Printer));
+  aMsgMgr->ChangePrinters().Append (aPrinters);
+
   return 0;
 }
 
index 9bf22b6..0114302 100644 (file)
 
 #include <DBRep.hxx>
 #include <Draw_Appli.hxx>
+#include <Draw_Printer.hxx>
 #include <IFSelect_Functions.hxx>
 #include <IFSelect_SessionPilot.hxx>
 #include <Interface_InterfaceModel.hxx>
 #include <Interface_Macros.hxx>
 #include <Interface_Protocol.hxx>
 #include <Message.hxx>
+#include <Message_Messenger.hxx>
+#include <Message_PrinterOStream.hxx>
 #include <Standard_Transient.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TColStd_HSequenceOfAsciiString.hxx>
@@ -48,14 +51,23 @@ static Handle(TColStd_HSequenceOfAsciiString) thenews;
 
 static Handle(IFSelect_SessionPilot)    thepilot;  // detient Session, Model
 
-static Standard_Integer XSTEPDRAWRUN (Draw_Interpretor& , Standard_Integer argc, const char** argv)
+static Standard_Integer XSTEPDRAWRUN (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
   TCollection_AsciiString mess;
   for (Standard_Integer i = 0; i < argc; i ++) {
     mess.AssignCat(argv[i]);  mess.AssignCat(" ");
   }
 
+  const Handle(Message_Messenger)& aMsgMgr = Message::DefaultMessenger();
+  Message_SequenceOfPrinters aPrinters;
+  aPrinters.Append (aMsgMgr->ChangePrinters());
+  aMsgMgr->AddPrinter (new Draw_Printer (di));
+
   IFSelect_ReturnStatus stat = thepilot->Execute (mess.ToCString());
+
+  aMsgMgr->RemovePrinters (STANDARD_TYPE(Draw_Printer));
+  aMsgMgr->ChangePrinters().Append (aPrinters);
+
   if (stat == IFSelect_RetError || stat == IFSelect_RetFail) return 1;
   else return 0;
 }
index 5f58c89..19365a8 100644 (file)
@@ -12,6 +12,7 @@ pload XSDRAW
 
 restore [locate_data_file OCC22765.brep] a
 vinit
+XProgress -tclOutput
 XProgress -t
 set List1 [sewing result 0.1 a]
 if { [string compare $List1 ""] != 0 } {
index da7d65a..e0adc02 100755 (executable)
@@ -10,6 +10,7 @@ set BugNumber OCC22572
 
 catch { pload XSDRAW }
 vinit
+XProgress -tclOutput
 XProgress -t
 set List1 [meshfromstl result [locate_data_file bearing.stl]]
 puts "----------------------"
index 8baeee9..7ca33e8 100755 (executable)
@@ -11,6 +11,7 @@ set BugNumber OCC22746
 catch { pload XSDRAW }
 restore [locate_data_file OCC22746-om.brep] a 
 vinit
+XProgress -tclOutput
 XProgress -t
 set List1 [fixshape result a]
 puts "----------------------"
index 141fd89..4318a9e 100755 (executable)
@@ -11,6 +11,7 @@ set BugNumber OCC22746
 catch { pload XSDRAW }
 restore [locate_data_file OCC22746-trampafus-notfixed.brep] a
 vinit
+XProgress -tclOutput
 XProgress -t
 set List1 [fixshape result a]
 puts "----------------------"
index aa24416..987fc6c 100755 (executable)
@@ -14,6 +14,7 @@ catch { pload XSDRAW }
 
 restore [locate_data_file OCC22761-TransmissionTestModel5-notfixed.brep] a 
 vinit
+XProgress -tclOutput
 XProgress -t
 set List1 [fixshape result a]
 puts "----------------------"