HxConnection.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_HXCONNECTION
42 #endif
43 #pragma warning(push)
44 #pragma warning(disable:4996)
45 
48 #ifndef HX_CONNECTION_H
49 #define HX_CONNECTION_H
50 
51 #include <mclib/McDArray.h>
52 #include <mclib/McVec2i.h>
53 #include <xpand/hxdefs/HxInternalRules.h>
54 #include <hxcore/HxPort.h>
55 
56 class HxCompModule;
57 class HxEditor;
58 class QPainter;
59 class QComboBox;
60 class QToolButton;
61 class QIcon;
62 class QxConnectionGUIUpdater;
63 
64 // Prototype for connection check methods.
65 typedef int (*SourceCheck)(void* userData, HxObject* src);
66 
78 class HXCORE_API HxConnection : public HxPort {
79 
80  HX_PORT(HxConnection);
81 
82 public:
90  HxConnection(HxObject*, const QString& name, const QString& label);
91 
99  HxConnection(HxObject*, const QString& name, const QString& label, const McTypeInfo* t);
100 
108  HxConnection(HxEditor* editor, const QString& name, const QString& label);
109 
117  HxConnection(HxEditor* editor, const QString& name, const QString& label, const McTypeInfo* t);
118 
122  virtual ~HxConnection();
123 
136  int validSource(HxObject* src);
137 
146  virtual bool connect(HxObject* src);
147 
153  void enableNotificationOnConnect(bool flag);
154 
160  bool isNotificationOnConnectEnabled() const;
161 
162 
168  virtual void disconnect(bool disconnectedDuringConnection=false);
169 
175  HxObject* getSource() const;
176 
186  McTypedObject* getSource(const McTypeInfo* t) const;
187 
194  bool isOptional();
195 
213  void setOptional(bool inFlag);
214 
224  HxINTERNAL bool isEditable() const;
225 
231  void allowEditing(bool onOff);
232 
247  void setVisibility(int cnxVisibility, bool popupCnxItemVisibility=true);
248 
255  HxINTERNAL bool isPopupCnxItemVisible() const;
256 
266  void setTightness(bool onOff);
267 
273  int isTight() const;
274 
280  void addType(const McTypeInfo* t);
281 
285  void clearTypes();
286 
299  void setSourceCheck(SourceCheck cb, void* userData);
300 
307  SourceCheck getSourceCheck(void*& userData);
308 
312  void sourceCheckChanged();
313 
322  virtual int parse(Tcl_Interp* interpreter, int argc, char **argv);
323 
329  virtual void saveState(FILE* fp);
330 
336  virtual void getState(QString& state) const;
337 
349  virtual int setState(const QString& state);
350 
357  HxINTERNAL virtual void drawConnection(QPainter* p, std::map<HxObject*, McDArray<std::pair<QPointF, QColor> > >& connectors);
358 
368  HxINTERNAL virtual int intersect(int x, int y);
369 
373  HxINTERNAL void feedback(QPainter*,int x, int y, HxObject* object);
374 
380  HxINTERNAL void confirm(HxObject* object);
381 
387  HxINTERNAL int mustBeDisplayedBeforeOtherPorts() const;
388 
394  HxINTERNAL QComboBox* getSourcesListCB() const;
395 
401  HxINTERNAL QToolButton* getGoToCurrentSourceBtn() const;
402 
409  HxINTERNAL void setVisibleGoToCurrentSourceBtn(bool visible);
410 
417  HxINTERNAL bool isVisibleGoToCurrentSourceBtn();
418 
424  HxINTERNAL QxConnectionGUIUpdater* getGUIUpdater() const;
425 
431  virtual void setLabel(const QString & text);
432 
433  /*
434  * Type info array type added for convenience.
435  */
436  typedef McDArray<const McTypeInfo*> TypeInfoArray;
437 
443  const TypeInfoArray& getValidTypes() const;
444 
450  virtual void initFrom(HxPort* refPort);
451 
457  inline void setMustBeDisplayedBeforeOtherPorts(bool force = true) {
458  m_mustBeDisplayedBeforeOtherPorts = force;
459  }
460 
461  HxINTERNAL virtual void createExternal(HxObject *object, int buildWidget);
462 
463  HxINTERNAL virtual void removeExternal(HxObject *object);
464 
470  void setAcceptCyclicConnection( const bool cyclicConnectionAccepted );
471 
475  bool acceptCyclicConnection() const;
476 
482  HxINTERNAL void setSaveConnection( bool canSaveConnection );
483 
489  HxINTERNAL bool canSaveConnection() const;
490 
491 protected:
492  bool editable;
493  bool optional;
494  bool notificationOnConnectEnabled;
495  bool tight;
496  HxObject* connected;
497  TypeInfoArray typeList;
498  void* userData;
499  SourceCheck sourceCheck;
500 
501  /*
502  * To know if the object connection item within the object popup menu in the pool is visible or not.
503  * This flag can be set by setVisibility(int cnxVisibility, bool modulePopupCnxItemVisibility).
504  */
505  bool m_connectionPopupItemVisibility;
506 
507  /*
508  * To know if the connection line in the pool is visible or not.
509  * This flag can be set by setVisibility(int cnxVisibility, bool modulePopupCnxItemVisibility).
510  */
511  unsigned int m_connectionLineVisibility:1;
512 
519  virtual void createWidget(QWidget* w);
520 
521 
522  HxINTERNAL static int defaultSourceCheck(void* userData, HxObject* source);
523 
524  /*
525  * To know if the connection gui must be displayed before the others ports.
526  * Default value is true. Inherited connections (like HxPortColormap, HxPortTime)
527  * which have their own gui must set this flag to false.
528  */
529  bool m_mustBeDisplayedBeforeOtherPorts;
530 
531  /*
532  * The sources list combo box.
533  */
534  QxGuardedPtr<QComboBox> m_sourcesListCB;
535 
536  /*
537  * The "Go to" tool button.
538  */
539  QxGuardedPtr<QToolButton> m_goToCurrentSourceBtn;
540 
541  /*
542  * To know if the goToCurrentSourceBtn must be displayed.
543  */
544  bool m_showGoToCurrentSourceBtn;
545 
546  /*
547  * The "Go to" tool button icon.
548  */
549  static QIcon* s_goToCurrentSourceIcon;
550 
554  void commonInit();
555 
556  /*
557  * Associated object pool listener used to update the gui.
558  */
559  QxConnectionGUIUpdater* m_guiUpdater;
560 
564  virtual void guiCallback();
565 
566 
567 private:
568 
569  /*
570  * @brief Add quotes surrounding the given string to protect spaces if necessary.
571  *
572  * @str the string to protect with quotes.
573  * @return the protected string
574  */
575  static QString addSurroundingQuotes( const QString& str );
576 
577  // Flag indicating if this connection accepts data connected to a downstream connection of its owner
578  bool m_acceptCyclicConnection;
579 
583  bool m_canSaveConnection;
584 
585 };
586 
587 template<class TYPE>
588 TYPE* hxconnection_cast (const HxConnection& connection) {
589  return static_cast<TYPE*> (connection.getSource(TYPE::getClassTypeId()));
590 }
591 
592 #endif
593 
594 
596 
597 #pragma warning(pop)
598 
599 #if defined(HX_INTERNAL_CLASS_WARN_HXCONNECTION)
600 #undef HX_INTERNAL_CLASS_WARN_HXCONNECTION
601 #define HX_INTERNAL_CLASS_WARN
602 #endif
void setMustBeDisplayedBeforeOtherPorts(bool force=true)
Control if the connection gui must be displayed before the others ports.
Definition: HxConnection.h:457
Port representing inter-object connections.
Definition: HxConnection.h:78
Base class for compute modules.
Definition: HxCompModule.h:77
HxObject * getSource() const
Returns object the port is connected to.