1 /*=========================================================================
2  *
3  *  Copyright Insight Software Consortium
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *         http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *=========================================================================*/
18 /*=========================================================================
19  *
20  *  Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  *  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  *  For complete copyright, license and disclaimer of warranty information
25  *  please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkOutputWindow_h
29 #define itkOutputWindow_h
30 
31 #include "itkObject.h"
32 
33 namespace itk
34 {
35 /** \class OutputWindow
36  * \brief Messages sent from the system are collected by this object.
37  *
38  * Text messages that the system should display to the user are sent to
39  * this object (or subclasses of this object).
40  *
41  * \ingroup OSSystemObjects
42  * \ingroup ITKCommon
43  */
44 class ITKCommon_EXPORT OutputWindow:public Object
45 {
46 public:
47   ITK_DISALLOW_COPY_AND_ASSIGN(OutputWindow);
48 
49   /** Standard class type aliases. */
50   using Self = OutputWindow;
51   using Superclass = Object;
52   using Pointer = SmartPointer< Self >;
53   using ConstPointer = SmartPointer< const Self >;
54 
55   /** Run-time type information (and related methods). */
56   itkTypeMacro(OutputWindow, Object);
57 
58   /** This is a singleton pattern New.  There will only be ONE
59    * reference to a OutputWindow object per process.  Clients that
60    * call this must call Delete on the object so that the reference
61    * counting will work.   The single instance will be unreferenced when
62    * the program exits. */
63   static Pointer New();
64 
65   /** Return the singleton instance with no reference counting. */
66   static Pointer GetInstance();
67 
68   /** Supply a user defined output window. Call ->Delete() on the supplied
69    * instance after setting it. */
70   static void SetInstance(OutputWindow *instance);
71 
72   /** Send a string to display. */
73   virtual void DisplayText(const char *);
74 
75   /** Send a string as an error message to display.
76    * The default implementation calls DisplayText() but subclasses
77    * could present this message differently. */
DisplayErrorText(const char * t)78   virtual void DisplayErrorText(const char *t) { this->DisplayText(t); }
79 
80   /** Send a string as a warningmessage to display.
81    * The default implementation calls DisplayText() but subclasses
82    * could present this message differently. */
DisplayWarningText(const char * t)83   virtual void DisplayWarningText(const char *t) { this->DisplayText(t); }
84 
85   /** Send a string as a message to display.
86    * The default implementation calls DisplayText() but subclasses
87    * could present this message differently. */
DisplayGenericOutputText(const char * t)88   virtual void DisplayGenericOutputText(const char *t) { this->DisplayText(t); }
89 
90   /** Send a string as a debug message to display.
91    * The default implementation calls DisplayText() but subclasses
92    * could present this message differently. */
DisplayDebugText(const char * t)93   virtual void DisplayDebugText(const char *t) { this->DisplayText(t); }
94 
95   /** If PromptUser is set to true then each time a line of text
96    * is displayed, the user is asked if they want to keep getting
97    * messages. */
98   itkSetMacro(PromptUser, bool);
99   itkGetConstMacro(PromptUser, bool);
100   itkBooleanMacro(PromptUser);
101 
102 protected:
103   OutputWindow();
104   ~OutputWindow() override;
105   void PrintSelf(std::ostream & os, Indent indent) const override;
106 
107 private:
108   bool           m_PromptUser;
109   static Pointer m_Instance;
110 };
111 } // end namespace itk
112 
113 #endif
114