HxBase.h
1 /*
2 Copyright 1999-2016 FEI, SAS
3 Copyright 1995-2016, ZIB Berlin
4 ALL RIGHTS RESERVED.
5 
6 AvizoŽ is a registered trademark of FEI, SAS
7 AmiraŽ is a registered trademark of ZIB.
8 
9 AvizoŽ and AmiraŽ are being jointly developed by Zuse Institute Berlin and FEI, SAS.
10 HardCopy, MeshViz, VolumeViz, TerrainViz are marks of FEI, SAS
11 FEI, SAS is a source licensee of OpenGLŽ, Open InventorŽ
12 from Silicon Graphics, Inc. OpenGLŽ and Open InventorŽ are
13 registered trademark of Silicon Graphics, Inc. All other products and
14 company names are trademarks or registered trademarks of
15 their respective companies.
16 
17 FEI, SAS accepts no liability to any
18 party for loss or damage caused by errors or omissions or by
19 statements of any kind in this publication, whether such errors
20 result from accident, negligence or any other cause. FEI assumes
21 no liability for incidental or consequential damages arising
22 from the use of information in this publication. FEI provides no
23 warranties regarding the information contained in this
24 publication, whether expressed, implied, or statutory, including
25 implied warranties of merchantability or fitness for a
26 particular purpose.
27 
28 FEI also does not assume any liability for links from this
29 publication to publications from other companies, organizations
30 or individuals. FEI does not imply endorsement of any specific
31 company, organization or individual through offering links to
32 this content. All information provided within this publication
33 is subject to change at any time and is provided for
34 informational purposes only by FEI. Copyright 1994-2016 by
35 FEI, SAS Merignac, France.
36 
37 */
38 
39 #if defined(HX_INTERNAL_CLASS_WARN)
40 #undef HX_INTERNAL_CLASS_WARN
41 #define HX_INTERNAL_CLASS_WARN_HXBASE
42 #endif
43 #pragma warning(push)
44 #pragma warning(disable:4996)
45 
48 #ifndef HX_BASE_H
49 #define HX_BASE_H
50 
51 #include <hxcore/api.h>
52 
53 #ifdef _WIN32
54 // warning C4355: 'this' : used in base member initializer list
55 #pragma warning( disable: 4355 )
56 #endif
57 
58 #include <stdarg.h>
59 #include <xpand/hxdefs/HxInternalRules.h>
60 #include <mclib/McDArray.h>
61 #include <mclib/McInterfaceOwner.h>
62 #include <mclib/McInterface.h>
63 #include <amiramesh/HxParseUtils.h>
64 
65 #include <set>
66 #include <map>
67 
68 class HxDisplay;
69 class SoNode;
70 class SoSeparator;
71 class SoTransform;
72 class SoRenderAreaSwitch;
73 class SoAction;
74 class SoFieldSensor;
75 class SoSensor;
76 class HxPort;
77 class HxPlanarModBase;
78 class HxObject;
79 class HxData;
80 class HxSpatialData;
81 class HxVolumeDataObject;
82 class HxBasePool;
83 class HxProjection;
84 class HxRenderArea;
85 class SoSwitch;
86 class HxBasePrivate;
87 class QString;
88 class QxBaseNotifier;
89 class HxPortTypeInfo;
90 
91 // Units management
92 
93 template<class T> class QxGlobalDisplayUnitsChangesListener;
94 
95 struct HxBaseTclMembersPriv;
96 
155 class HXCORE_API HxBase : public McInterface {
156 
157  MC_ABSTRACT_HEADER(HxBase);
158 
159  public:
160 
164  enum Flags{
165  CAN_BE_CLIPPED = 0,
170  NUM_HXBASE_FLAGS
171  };
172 
182  virtual void setLabel(const QString& label);
183 
186  virtual void setDisplayLabel( const QString& displayLabel );
187 
189  inline const QString& getDisplayLabel() const { return theDisplayLabel; }
190 
191 
198  const QString& getLabel(bool withDoubleQuotes=false) const;
199 
206  const char* getName(bool withDoubleQuotes=false) const;
207 
228  static QString convertToCamelCase( const char* name );
229 
235  const QString& getCamelCaseLabel() const;
236 
245  virtual bool isCamelCaseSupported() const;
246 
257  void composeLabel(const QString& otherLabel, const QString& replacement);
258 
272  virtual void setViewerMask(int mask, int masterMask=0xffffffff);
273 
280  int getViewerMask() const;
281 
287  int getViewerMaskAsIs() const;
288 
294  int getViewerMasterMask() const;
295 
303  void copyViewerVisibility(unsigned int fromViewerId, unsigned int toViewerId);
304 
311  static int getDefaultViewerMask();
312 
324  void showGeom(SoNode *node, HxSpatialData* controllData);
325 
331  virtual void showGeom(SoNode *node);
332 
339  void hideGeom(SoNode *node);
340 
349  virtual void clipGeom(HxPlanarModBase* planarMod, int viewerMask = 0xffff);
350 
356  virtual void unclipGeom(HxPlanarModBase* planarMod);
357 
363  bool isClipped() const;
364 
372  int getClipperMask(HxPlanarModBase* planarMod);
373 
382  virtual int parse(Tcl_Interp* interpreter, int argc, char **argv);
383 
389  static int getNumInstances();
390 
396  void setControllingData(HxSpatialData* data);
397 
403  HxSpatialData* getControllingData() const;
404 
410  void showPinButtons( bool showIt );
411 
417  int getNumPorts() const;
418 
425  HxPort* getPort(int i) const;
426 
433  HxPort* getPort( const QString& name) const;
434 
441  HxPort* getPortByLabel( const QString& label) const;
442 
450  HxPort* getPortOfType( const McTypeInfo *type, bool ignoreInvisible=true ) const;
451 
452  // Propagated interface of HxBasePool
453 
459  static void addForbiddenLabel(const char* forbiddenLabel);
460 
466  static void removeForbiddenLabel(const char* forbiddenLabel);
467 
471  static void removeAllForbiddenLabels();
472 
478  HxINTERNAL void saveTclMemberVars(FILE* fp);
479 
487  bool getTclMemberVar(const char *name, QString& result) const;
488 
495  void setTclMemberVar(const char *name, const char* value);
496 
504  HxINTERNAL int setTclMemberVarSerialize(const char *name, bool serialize);
505 
506 
507  HxINTERNAL int unsetTclMemberVar(const char *name);
508 
509  HxINTERNAL int hasTclMemberFunction(const char *name);
510 
511  HxINTERNAL void undefineTclMemberFunctions();
512 
513  HxINTERNAL const char* defineTclMemberFunction(const char *name, const char* args,
514  const char* body);
515  HxINTERNAL void clearTclMembers();
516  HxINTERNAL int callTclMemberFunction(const char *name, const char* args, QString& result);
517 
525  SoSeparator* getSeparator() const;
526 
530  virtual void checkRemoteMode();
531 
535  HxINTERNAL virtual int getGeometryWeight();
536 
553  void setRequiresPolygonOffset(bool value);
554 
560  bool requiresPolygonOffset() const;
561 
571  static bool polygonOffsetRequired();
572 
579  virtual void setDisplayViewers(const std::set<int>& visibleAreas);
580 
587  void setDisplayViewers(const McDArray<int>& visibleAreas);
588 
596  void getDisplayViewers(std::set<int>& visibleAreas) const;
597 
604  void setDisplay(HxDisplay *display);
605 
611  HxDisplay *getDisplay();
612 
619  virtual const QxBaseNotifier* getNotifier() const;
620 
622 
627  void notifyPortAdded(HxPort* port);
628  void notifyPortRemoved(HxPort* port);
630 
631 
632  /**********************/
634  /**********************/
635 
641  QxGlobalDisplayUnitsChangesListener<HxBase>* getDisplayUnitsChangesListener() const;
642 
650  virtual void globalUnitChanged(const int& oldUnit, const int& newUnit);
651 
659  virtual void globalCoordinatesUnitChanged(const int& oldUnit, const int& newUnit);
660 
667  bool getFlag( unsigned int flag ) const;
668 
675  void setFlag( unsigned int flag, bool value );
676 
685  static QString translate( const char * context, const char * sourceText, const char * disambiguation = 0);
686 
687  /*
688  * @name On-the-fly port factory
689  *
690  * The 4 following function add the notion of on-the-fly port:
691  *
692  * Usually, ports are defined as inner object of a class inheriting from HxBase: example:
693  *
694  * class HxSomeModule
695  * {
696  * public:
697  * HxPortButtonMenu portButtonMenu;
698  * };
699  *
700  * The compiler is aware at compile-time which port belongs to each module and they are
701  * statically allocated. (as inner-objects)
702  *
703  * An on-the-fly port is a port that can be added at runtime. Such a port is still listed
704  * in the usual member variables allPorts and will be saved as an usual port. But as they are
705  * instantiated dynamically, the inner variable m_allOnTheFlyPorts keep a list of all on-the-fly
706  * ports that must be deleted by HxBase. Consequently, an on-the-fly port has a life-time bound
707  * to the lifetime of the HxBase used to instantiate.
708  *
709  */
710 
723  HxINTERNAL HxPort* createOnTheFlyPortFromClassName(const QString& className, const QString& name, const QString& label);
724 
738  HxINTERNAL virtual HxPort* createOnTheFlyPort(const HxPortTypeInfo* typeInfo, const QString& name, const QString& label);
739 
745  HxINTERNAL void removeOnTheFlyPort(HxPort* port);
746 
750  HxINTERNAL void removeAllOnTheFlyPorts();
751 
752 protected:
764  HxINTERNAL HxBase(McInterfaceOwner* owner = 0, QxBaseNotifier* notifier = 0);
765 
771  HxINTERNAL virtual ~HxBase();
772 
778  void useWorldCoords(int trueOrFalse=1);
779 
783  virtual void updateTransform();
784 
785  // Pointer to the transformation node of the controlling data object.
786  SoTransform* globalToLocalTransform;
787 
788  // This is zero if the object uses world coords.
789  SoTransform* globalToWorldTransform;
790 
791  // Unique label of the object, also used as Tcl command name.
792  QString theLabel;
793  QString theLabelWithDoubleQuotes;
794  QString theLabelCamelCase;
795 
796  // Label that is displayed in the GUI icon, does not need to be unique
797  QString theDisplayLabel;
798 
799  // Transform matrix of @c controllingData will be used for this object.
800  HxSpatialData* controllingData;
801 
802  // List of all ports of this object.
803  McDArray<HxPort*> allPorts;
804 
805  /*
806  * List of all ports created on-the-fly.
807  * All on-the-fly port are listed in allPorts too. The purpose of this vector
808  * is to keep a track of all ports that have been instantiated dynamically
809  * in order to destroy them in the HxBase dtor. Usual port don't need to be deleted
810  * as they are inner-object of some class inheriting from HxBase.
811  */
812  std::vector<HxPort*> m_allOnTheFlyPorts;
813 
814  // This node holds all geometry generated by the object.
815  SoSeparator* root;
816 
817  // This node holds geometry created by inherited classes and
818  // added to this node by using @c showGeom method.
819  SoRenderAreaSwitch* raSwitch;
820 
821  //Be notified on "on" @c raSwitch field modification
822  SoFieldSensor* raSwitchOnSensor;
823 
824  // This class holds display properties & ports
825  HxDisplay *m_display;
826 
827  // Defines in which viewer geometry is visible.
828  unsigned short viewerMask;
829  unsigned short viewerMasterMask;
830 
831  // used by Scaleviz depth composing.
832  // Use zero to prevent a geometry to be rendered on one dedicated slave.
833  int m_geometryWeight;
834 
835  typedef struct
836  {
837  SoRenderAreaSwitch* clipSwitch;
838  SoFieldSensor* clipSwitchOnSensor;
839  int viewerMask;
840  } ClipperInfo;
841 
842  // List of clipping planes applied to the output of this object.
843  std::map<HxPlanarModBase*, ClipperInfo> clipperList;
844 
854  static int staticParse(ClientData data, Tcl_Interp* interpreter, int argc, char** argv);
855 
856  /*
857  * The list of areas in which this module (the scene graph contain within this module)
858  * must be visible.
859  * We use a set to be sure that each element is unique and to benefit of the find capability
860  * of the set.
861  */
862  std::set<int> m_visibleAreas;
863 
867  virtual void projectionActivated();
868 
872  virtual void projectionDeactivated();
873 
879  bool containsNode();
880 
884  HxINTERNAL void deleteSceneGraph();
885 
896  virtual void addRootToController(SoSeparator* rootSep, int rootViewerMask = 0xffff);
897 
904  virtual void removeRootFromController(SoSeparator* rootSep);
905 
912  HxINTERNAL static int renderAreaSwitchStaticCB(void* localUserData, HxBase* moduleBase, SoSwitch* traversingSwitch, HxRenderArea* renderArea, SoAction* action);
913 
924  virtual int renderAreaSwitchCB(SoSwitch* traversingSwitch, HxRenderArea* renderArea, SoAction* action);
925 
930  HxINTERNAL int handleRenderAreaSwitchTraversing(const std::set<int>& visibleAreas, SoSwitch* traversingSwitch, HxRenderArea* renderArea, SoAction* action);
931 
935  HxINTERNAL static void raSwitchOnSensorCB(void* data, SoSensor* sensor);
936 
946  HxINTERNAL void handleNewDisplayViewersList(std::set<int>& visibleAreas);
947 
948  /*
949  * Array of object's flags. Inherited modules can add custom flags.
950  */
951  McDArray<bool> m_flags;
952 
953 
954  // Units management
955 
956  // QxGlobalDisplayUnitsChangesListener object which listen to global display units changes signals.
957  QxGlobalDisplayUnitsChangesListener<HxBase>* m_displayUnitsChangesListener;
958 
962  virtual void initScenegraph();
963 
964  private:
973  int parseAllInterfaces( Tcl_Interp* t, int argc, char** argv );
974 
975  HxBaseTclMembersPriv* tclMembers;
976 
977  // private implementation of HxBase.
978  HxBasePrivate* m_private;
979 
980  QByteArray theLabelQBA;
981  QByteArray theLabelWithDoubleQuotesQBA;
982  QByteArray theLabelCamelCaseQBA;
983 
984  /* Private method to set the label and register it as a Tcl command.
985  (W)ithout (D)eleting (O)r (U)nique (C)heck, */
986  void setLabelWDOUC(const char* label);
987 
988  public:
992  HxINTERNAL void internalSetLabel(const char* label);
993 
994  friend class HxPort;
995  friend class HxSpatialData;
996  friend class HxBasePool;
997  friend class HxProjection;
998  friend class HxBasePrivate;
999 };
1000 
1001 /*
1002  * The following macros are defined for backward compatibilty
1003  */
1004 
1005 /*
1006  * @page HxBaseRelatedMacros HxBase - related macros
1007  * Some macros used with classes derived from HxBase.
1008  * Since HxBase is derived from McTypedObject you <b> must not</b>
1009  * forget to use one of the macros defined in
1010  * @ref McTypedObject RelatedMacros "McTypedObject - related macros" in your class declaration and
1011  * definition. The macros defined <em> above</em> are exactly the same,
1012  * only use the <b> HX</b> notation.
1013  * See @ref McTypedObject RelatedMacros "McTypedObject - related macros" or McTypedObject
1014  * for more details.
1015  */
1016 
1017 /*
1018  * @name Macros, used in the class declaration
1019  */
1021 /* Same as @c MC_ABSTRACT_HEADER(className).*/
1022 #define HX_ABSTRACT_HEADER(className) \
1023  MC_ABSTRACT_HEADER(className); \
1024  static inline QString tr(const char *s, const char *c = 0, const char *dummy=0) { dummy = 0; return HxBase::translate(#className, s, c); }
1025 /* Same as @c MC_HEADER(className).*/
1026 #define HX_HEADER(className) \
1027  MC_HEADER(className); \
1028  static inline QString tr(const char *s, const char *c = 0, const char *dummy=0) { dummy = 0; return HxBase::translate(#className, s, c); }
1029 /* Same as @c MC_TEMPLATE_HEADER(className).*/
1030 #define HX_TEMPLATE_HEADER(className) \
1031  MC_TEMPLATE_HEADER(className); \
1032  static inline QString tr(const char *s, const char *c = 0, const char *dummy=0) { dummy = 0; return HxBase::translate(#className, s, c); }
1033 
1034 
1035 /*
1036  * @name Macros, used in the class definition
1037  */
1039 /* Same as @c MC_ABSTRACT_CLASS(className,parentClass).*/
1040 #define HX_INIT_ABSTRACT_CLASS(className,parentClass) \
1041  MC_INIT_ABSTRACT_CLASS(className,parentClass);
1042 
1043 /* Same as @c MC_ABSTRACT_CLASS2(className,parent1,parent2).*/
1044 #define HX_INIT_ABSTRACT_CLASS2(className,parent1,parent2)\
1045  MC_INIT_ABSTRACT_CLASS2(className,parent1,parent2);
1046 
1047 /* Same as @c MC_INIT_CLASS(className,parentClass).*/
1048 #define HX_INIT_CLASS(className,parentClass)\
1049  MC_INIT_CLASS(className,parentClass);
1050 
1051 /* Same as @c MC_INIT_TEMPLATE_CLASS(className,parentClass).*/
1052 #define HX_INIT_TEMPLATE_CLASS(className,parentName) \
1053  MC_INIT_TEMPLATE_CLASS(className,parentName);
1054 
1055 /* Same as @c MC_INIT_CLASS2(className,parent1,parent2).*/
1056 #define HX_INIT_CLASS2(className,parent1,parent2)\
1057  MC_INIT_CLASS2(className,parent1,parent2);
1058 
1059 
1067 extern HXCORE_API void setResultName(QString& result,
1068  const QString& originalName, const QString& replacement);
1069 
1070 #endif
1071 
1073 
1074 #pragma warning(pop)
1075 
1076 #if defined(HX_INTERNAL_CLASS_WARN_HXBASE)
1077 #undef HX_INTERNAL_CLASS_WARN_HXBASE
1078 #define HX_INTERNAL_CLASS_WARN
1079 #endif
Object can have console completion.
Definition: HxBase.h:168
Object can be clipped by other modules.
Definition: HxBase.h:166
HXCORE_API void setResultName(QString &result, const QString &originalName, const QString &replacement)
Set result name.
const QString & getDisplayLabel() const
Returns the object&#39;s display label.
Definition: HxBase.h:189
Object visibility can be copied from one viewer to another.
Definition: HxBase.h:167
Flags
Flags.
Definition: HxBase.h:164
Base class of all data objects, modules, and editors.
Definition: HxBase.h:155