Draw force elements
DrawForceElementsWindow.h
// Copyright 2010 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 



#ifndef __DRAW_FORCE_ELEMENTS_WINDOW__H__
#define __DRAW_FORCE_ELEMENTS_WINDOW__H__


#include <ArcSDK.h>
#include <Ao/AoControls.h>
#include <AxCtl/qt4axctl.h>
#include <olb/esridefensesolutions.h>

#include <QtGui/QtGui>
#include <list>

#define NUM_FE_TYPES 4


// the application's main window
class DrawForceElementsWindow : public QWidget, IMapControlEvents2Helper
{
    Q_OBJECT


    // modes controlled by the radio buttons
    enum UIMode
    {
        c_uiModeArcGIS,
        c_uiModePlaceFE,
        c_uiModeEditFE
    };


    // private state variables
    double                         m_angle;
    QPushButton                   *m_btnClear;
    QPushButton                   *m_btnDelete;
    QPushButton                   *m_btnExport;
    QCheckBox                     *m_chkRandomizeSIC;
    QComboBox                     *m_cmbPropName;
    QWidget                       *m_controlPanel;
    std::list<ICachedGraphic*>     m_forceElements;
    char                           m_forceElementType;
    IRgbColorPtr                   m_ipHighlightColor;
    IMapControl4Ptr                m_ipMapControl;
    IEventListenerHelperPtr        m_ipMapControlEventsHelper;
    IEnvelopePtr                   m_ipRefreshEnvelope;
    IForceElement2525BRendererPtr  m_ipRenderer;
    ICachedGraphicPtr              m_ipSelectedFE;
    IToolbarControlPtr             m_ipToolbarControl;
    QStringList                    m_labelPlacements;
    QLabel                        *m_lblHint;
    QLabel                        *m_lblPlacement;
    bool                           m_mouseDown;
    double                         m_prevX;
    double                         m_prevY;
    QRadioButton                  *m_rbFEType[NUM_FE_TYPES];
    QSlider                       *m_sldSize;
    bool                           m_suppressChangeFEType;
    QLineEdit                     *m_txtPropValue;
    QLineEdit                     *m_txtSIC;
    UIMode                         m_uiMode;

    // utility functions
    void              addRefresh       (ICachedGraphicPtr ipFE);
    void              addTool          (const char *name);
    double            computeSize      ();
    void              copyPropToText   ();
    void              copySICToText    ();
    void              copyTextToProp   ();
    void              copyTextToSIC    ();
    void              enableDisable    ();
    IActiveViewPtr    getActiveView    ();
    IScreenDisplayPtr getScreenDisplay (IActiveViewPtr ipActiveView = 0);
    void              resetRefresh     (ICachedGraphicPtr ipFE = 0);

public slots:


    void changeAngle    (int sliderValue);
    void changeFEType   (int radioButtonID);
    void changeMode     (int radioButtonID);
    void changePropName (int newPropIndex);
    void changePropText (const QString&);
    void changeSICText  (const QString&);
    void changeSize     (int);
    void clearFE        ();
    void deleteFE       ();
    void exportFE       ();
    void randomizeSIC   ();


public:


    // this object will live longer than any COM object it contains - macro defined in sdkcomdef.h
  HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObj) { return S_OK; }
  ULONG   __stdcall AddRef()                                   { return 0;    }
  ULONG   __stdcall Release()                                  { return 0;    }


#if defined(ESRI_UNIX)
    // unused events from IMapControlEvents2
    virtual void OnAfterScreenDraw   (long)                                                           {}
    virtual void OnBeforeScreenDraw  (long)                                                           {}
    virtual void OnDoubleClick       (long, long, long, long, double, double)                         {}
    virtual void OnExtentUpdated     (VARIANT, VARIANT_BOOL, VARIANT)                                 {}
    virtual void OnFullExtentUpdated (VARIANT, VARIANT)                                               {}
    virtual void OnKeyDown           (long, long)                                                     {}
    virtual void OnKeyUp             (long, long)                                                     {}
    virtual void OnMapReplaced       (VARIANT)                                                        {}
    virtual void OnOleDrop           (esriControlsDropAction, VARIANT, long*, long, long, long, long) {}
    virtual void OnSelectionChanged  ()                                                               {}
    virtual void OnViewRefreshed     (VARIANT, long, VARIANT, VARIANT)                                {}

    // implemented events from IMapControlEvents2
    virtual void OnAfterDraw (VARIANT display, long viewDrawPhase);
    virtual void OnMouseDown (long button, long shift, long x, long y, double mapX, double mapY);
    virtual void OnMouseMove (long button, long shift, long x, long y, double mapX, double mapY);
    virtual void OnMouseUp   (long button, long shift, long x, long y, double mapX, double mapY);

#elif defined(ESRI_WINDOWS)
    // unused events from IMapControlEvents2
    virtual void __stdcall OnAfterScreenDraw   (long)                                                           {}
    virtual void __stdcall OnBeforeScreenDraw  (long)                                                           {}
    virtual void __stdcall OnDoubleClick       (long, long, long, long, double, double)                         {}
    virtual void __stdcall OnExtentUpdated     (VARIANT, VARIANT_BOOL, VARIANT)                                 {}
    virtual void __stdcall OnFullExtentUpdated (VARIANT, VARIANT)                                               {}
    virtual void __stdcall OnKeyDown           (long, long)                                                     {}
    virtual void __stdcall OnKeyUp             (long, long)                                                     {}
    virtual void __stdcall OnMapReplaced       (VARIANT)                                                        {}
    virtual void __stdcall OnOleDrop           (esriControlsDropAction, VARIANT, long*, long, long, long, long) {}
    virtual void __stdcall OnSelectionChanged  ()                                                               {}
    virtual void __stdcall OnViewRefreshed     (VARIANT, long, VARIANT, VARIANT)                                {}

    // implemented events from IMapControlEvents2
    virtual void __stdcall OnAfterDraw (VARIANT display, long viewDrawPhase);
    virtual void __stdcall OnMouseDown (long button, long shift, long x, long y, double mapX, double mapY);
    virtual void __stdcall OnMouseMove (long button, long shift, long x, long y, double mapX, double mapY);
    virtual void __stdcall OnMouseUp   (long button, long shift, long x, long y, double mapX, double mapY);
#endif

    // constructor and destructor to set up the GUI and dereference objects
             DrawForceElementsWindow();
    virtual ~DrawForceElementsWindow();
};


#endif // __DRAW_FORCE_ELEMENTS_WINDOW__H__