PCL
View.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/View.h - Released 2024-06-18T15:48:54Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_View_h
53 #define __PCL_View_h
54 
56 
57 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
58 
59 #include <pcl/Defs.h>
60 
61 #include <pcl/Array.h>
62 #include <pcl/Histogram.h>
64 #include <pcl/ImageVariant.h>
65 #include <pcl/Property.h>
66 #include <pcl/UIObject.h>
67 #include <pcl/Variant.h>
68 
69 namespace pcl
70 {
71 
72 // ----------------------------------------------------------------------------
73 
74 class PCL_CLASS ImageWindow;
75 
76 // ----------------------------------------------------------------------------
77 
82 // ----------------------------------------------------------------------------
83 
146 namespace ViewPropertyAttribute
147 {
148  enum mask_type
149  {
150  WriteProtected = 0x00000001,
151  ReadProtected = 0x00000002,
152  Volatile = 0x00000010,
153  Permanent = 0x00000020,
154  NotSerializable = 0x00000040,
155  Storable = 0x00000080,
156  Reserved = 0x10000000,
157  Protected = 0x20000000,
158  NoChange = 0x80000000
159  };
160 }
161 
167 
168 // ----------------------------------------------------------------------------
169 
212 class PCL_CLASS View : public UIObject
213 {
214 public:
215 
222 
227  View() = default;
228 
238  View( const View& v )
239  : UIObject( v )
240  {
241  }
242 
250  ~View() override
251  {
252  }
253 
258  static View& Null();
259 
264  bool IsMainView() const;
265 
270  bool IsPreview() const;
271 
276  bool IsPartialPreview() const;
277 
282  bool IsCompletePreview() const;
283 
290  bool IsVolatilePreview() const;
291 
298  bool IsStoredPreview() const;
299 
304 
313  IsoString Id() const;
314 
331  IsoString FullId() const;
332 
343  void Rename( const IsoString& newId );
344 
345  void Rename( const IsoString::ustring_base& newId )
346  {
347  Rename( IsoString( newId ) );
348  }
349 
353  bool CanRead() const;
354 
358  bool CanWrite() const;
359 
382  void Lock( bool notify = true ) const;
383 
399  void Unlock( bool notify = true ) const;
400 
415  void LockForWrite( bool notify = true ) const;
416 
417  /*
418  * Unlocks this view for write operations only.
419  * ### Undocumented (i.e., harmful) function.
420  */
421  void UnlockForWrite( bool notify = true ) const;
422 
445  void UnlockForRead( bool notify = true ) const;
446 
453  void RelockForRead( bool notify = true ) const;
454 
459  bool IsDynamicTarget() const;
460 
481 
491 
509 
516  {
517  return this->Image();
518  }
519 
524  bool IsColor() const;
525 
530  void GetSize( int& width, int& height ) const;
531 
535  int Width() const
536  {
537  int w, dum; GetSize( w, dum ); return w;
538  }
539 
543  int Height() const
544  {
545  int dum, h; GetSize( dum, h ); return h;
546  }
547 
554  Rect Bounds() const
555  {
556  int w, h; GetSize( w, h ); return Rect( w, h );
557  }
558 
573 
586  void SetScreenTransferFunctions( const stf_list&, bool notify = true );
587 
591  void DestroyScreenTransferFunctions( bool notify = true );
592 
598 
604  void EnableScreenTransferFunctions( bool = true, bool notify = true );
605 
611  void DisableScreenTransferFunctions( bool disable = true, bool notify = true )
612  {
613  EnableScreenTransferFunctions( !disable, notify );
614  }
615 
632  static bool IsReservedViewPropertyId( const IsoString& id );
633 
644 
652 
664 
676 
691 
722  void SetProperties( const PropertyArray& properties, bool notify = true,
723  ViewPropertyAttributes attributes = ViewPropertyAttribute::NoChange );
724 
743  void SetStorableProperties( const PropertyArray& properties, bool notify = true )
744  {
745  SetProperties( properties, notify,
746  ViewPropertyAttribute::Storable
747  | ViewPropertyAttribute::NoChange );
748  }
749 
771  void SetStorablePermanentProperties( const PropertyArray& properties, bool notify = true )
772  {
773  SetProperties( properties, notify,
774  ViewPropertyAttribute::Storable
775  | ViewPropertyAttribute::Permanent
776  | ViewPropertyAttribute::NoChange );
777  }
778 
792  Variant PropertyValue( const IsoString& property ) const;
793 
794  Variant PropertyValue( const IsoString::ustring_base& property ) const
795  {
796  return PropertyValue( IsoString( property ) );
797  }
798 
823  Variant ComputeProperty( const IsoString& property, bool notify = true );
824 
825  Variant ComputeProperty( const IsoString::ustring_base& property, bool notify = true )
826  {
827  return ComputeProperty( IsoString( property ), notify );
828  }
829 
846  template <class S>
847  Variant ComputeOrFetchProperty( const S& property, bool notify = true )
848  {
849  IsoString propertyId( property );
850  if ( HasProperty( propertyId ) )
851  return PropertyValue( propertyId );
852  return ComputeProperty( propertyId, notify );
853  }
854 
880  void SetPropertyValue( const IsoString& property, const Variant& value, bool notify = true,
881  ViewPropertyAttributes attributes = ViewPropertyAttribute::NoChange );
882 
883  void SetPropertyValue( const IsoString::ustring_base& property, const Variant& value, bool notify = true,
884  ViewPropertyAttributes attributes = ViewPropertyAttribute::NoChange )
885  {
886  SetPropertyValue( IsoString( property ), value, notify, attributes );
887  }
888 
906  void SetStorablePropertyValue( const IsoString& property, const Variant& value, bool notify = true )
907  {
908  SetPropertyValue( property, value, notify,
909  ViewPropertyAttribute::Storable
910  | ViewPropertyAttribute::NoChange );
911  }
912 
913  void SetStorablePropertyValue( const IsoString::ustring_base& property, const Variant& value, bool notify = true )
914  {
915  SetStorablePropertyValue( IsoString( property ), value, notify );
916  }
917 
937  void SetStorablePermanentPropertyValue( const IsoString& property, const Variant& value, bool notify = true )
938  {
939  SetPropertyValue( property, value, notify,
940  ViewPropertyAttribute::Storable
941  | ViewPropertyAttribute::Permanent
942  | ViewPropertyAttribute::NoChange );
943  }
944 
945  void SetStorablePermanentPropertyValue( const IsoString::ustring_base& property, const Variant& value, bool notify = true )
946  {
947  SetStorablePropertyValue( IsoString( property ), value, notify );
948  }
949 
965  Variant::data_type PropertyType( const IsoString& property ) const;
966 
967  Variant::data_type PropertyType( const IsoString::ustring_base& property ) const
968  {
969  return PropertyType( IsoString( property ) );
970  }
971 
985 
986  ViewPropertyAttributes PropertyAttributes( const IsoString::ustring_base& property ) const
987  {
988  return PropertyAttributes( IsoString( property ) );
989  }
990 
1006  void SetPropertyAttributes( const IsoString& property, ViewPropertyAttributes attributes, bool notify = true );
1007 
1008  void SetPropertyAttributes( const IsoString::ustring_base& property, ViewPropertyAttributes attributes, bool notify = true )
1009  {
1010  SetPropertyAttributes( IsoString( property ), attributes, notify );
1011  }
1012 
1018  bool HasProperty( const IsoString& property ) const;
1019 
1020  bool HasProperty( const IsoString::ustring_base& property ) const
1021  {
1022  return HasProperty( IsoString( property ) );
1023  }
1024 
1035  void DeleteProperty( const IsoString& property, bool notify = true );
1036 
1037  void DeleteProperty( const IsoString::ustring_base& property, bool notify = true )
1038  {
1039  DeleteProperty( IsoString( property ), notify );
1040  }
1041 
1049  void DeletePropertyIfExists( const IsoString& property, bool notify = true )
1050  {
1051  if ( HasProperty( property ) )
1052  DeleteProperty( property, notify );
1053  }
1054 
1055  void DeletePropertyIfExists( const IsoString::ustring_base& property, bool notify = true )
1056  {
1057  DeletePropertyIfExists( IsoString( property ), notify );
1058  }
1059 
1067  template <class S>
1068  static bool IsValidViewId( const S& id )
1069  {
1070  size_type p = id.Find( "->" );
1071  if ( p == String::notFound )
1072  return id.IsValidIdentifier();
1073  return id.Left( p ).IsValidIdentifier() && id.Substring( p+2 ).IsValidIdentifier();
1074  }
1075 
1080  static View ViewById( const IsoString& fullId );
1081 
1082  static View ViewById( const IsoString::ustring_base& fullId )
1083  {
1084  return ViewById( IsoString( fullId ) );
1085  }
1086 
1091  static Array<View> AllViews( bool excludePreviews = false );
1092 
1097 
1098 protected:
1099 
1100  View( void* h ) : UIObject( h )
1101  {
1102  }
1103 
1104  View( const void* h ) : UIObject( h )
1105  {
1106  }
1107 
1108  View( std::nullptr_t ) : UIObject( nullptr )
1109  {
1110  }
1111 
1112  friend class ImageWindow;
1113  friend class ProcessImplementation; // for LaunchOn()
1114  friend class ProcessInterface; // for event broadcasting functions
1115  friend class ProcessInstance; // for ExecuteOn() and related functions
1116  friend class ViewList;
1117  friend class ViewListEventDispatcher;
1118  friend class ControlEventDispatcher;
1119  friend class ProcessContextDispatcher;
1120  friend class InterfaceDispatcher;
1121  friend class InternalViewEnumerator;
1122  friend class InternalPreviewEnumerator;
1123 };
1124 
1125 // ----------------------------------------------------------------------------
1126 
1127 } // pcl
1128 
1129 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
1130 
1131 #endif // __PCL_View_h
1132 
1133 // ----------------------------------------------------------------------------
1134 // EOF pcl/View.h - Released 2024-06-18T15:48:54Z
A type-safe collection of enumerated flags.
Definition: Flags.h:85
Implements a generic, two-dimensional, shared or local image.
Definition: Image.h:278
A generic rectangle in the two-dimensional space.
Definition: Rectangle.h:314
Acts like a union for all types of images in PCL, with optional class-wide ownership of transported i...
Definition: ImageVariant.h:322
High-level interface to an image window object in the PixInsight core application.
Definition: ImageWindow.h:287
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5425
Root base class for all user interface objects.
Definition: UIObject.h:95
Acts like a union to store instances of different data types.
Definition: Variant.h:332
High-level interface to a PixInsight view object.
Definition: View.h:213
void Unlock(bool notify=true) const
void UnlockForRead(bool notify=true) const
int Width() const
Definition: View.h:535
void SetScreenTransferFunctions(const stf_list &, bool notify=true)
bool IsStoredPreview() const
ImageVariant GetImage() const
Definition: View.h:515
IsoString Id() const
void DestroyScreenTransferFunctions(bool notify=true)
void GetScreenTransferFunctions(stf_list &) const
void DisableScreenTransferFunctions(bool disable=true, bool notify=true)
Definition: View.h:611
bool AreScreenTransferFunctionsEnabled() const
IsoString FullId() const
void GetSize(int &width, int &height) const
bool IsColor() const
ImageWindow Window() const
View(const View &v)
Definition: View.h:238
void RelockForRead(bool notify=true) const
void AddToDynamicTargets()
void Lock(bool notify=true) const
ImageVariant Image() const
Rect Bounds() const
Definition: View.h:554
static View ViewById(const IsoString &fullId)
bool IsMainView() const
void RemoveFromDynamicTargets()
bool IsPreview() const
void Rename(const IsoString &newId)
~View() override
Definition: View.h:250
static View & Null()
bool IsDynamicTarget() const
void EnableScreenTransferFunctions(bool=true, bool notify=true)
static Array< View > AllViews(bool excludePreviews=false)
static Array< View > AllPreviews()
int Height() const
Definition: View.h:543
static bool IsValidViewId(const S &id)
Definition: View.h:1068
void LockForWrite(bool notify=true) const
bool CanWrite() const
bool IsVolatilePreview() const
bool IsCompletePreview() const
View()=default
bool CanRead() const
bool IsPartialPreview() const
size_t size_type
Definition: Defs.h:609
ViewPropertyAttributes PropertyAttributes(const IsoString &property) const
void SetStorableProperties(const PropertyArray &properties, bool notify=true)
Definition: View.h:743
static bool IsReservedViewPropertyId(const IsoString &id)
PropertyArray Properties() const
bool HasProperty(const IsoString &property) const
void SetStorablePermanentProperties(const PropertyArray &properties, bool notify=true)
Definition: View.h:771
PropertyArray StorableProperties() const
void SetStorablePermanentPropertyValue(const IsoString &property, const Variant &value, bool notify=true)
Definition: View.h:937
Variant PropertyValue(const IsoString &property) const
PropertyArray StorablePermanentProperties() const
PropertyArray PermanentProperties() const
void DeleteProperty(const IsoString &property, bool notify=true)
void SetPropertyAttributes(const IsoString &property, ViewPropertyAttributes attributes, bool notify=true)
Variant::data_type PropertyType(const IsoString &property) const
void SetProperties(const PropertyArray &properties, bool notify=true, ViewPropertyAttributes attributes=ViewPropertyAttribute::NoChange)
void SetPropertyValue(const IsoString &property, const Variant &value, bool notify=true, ViewPropertyAttributes attributes=ViewPropertyAttribute::NoChange)
PropertyDescriptionArray PropertyDescriptions() const
Variant ComputeOrFetchProperty(const S &property, bool notify=true)
Definition: View.h:847
void SetStorablePropertyValue(const IsoString &property, const Variant &value, bool notify=true)
Definition: View.h:906
Variant ComputeProperty(const IsoString &property, bool notify=true)
void DeletePropertyIfExists(const IsoString &property, bool notify=true)
Definition: View.h:1049
PCL root namespace.
Definition: AbstractImage.h:77