#ifndef __CPAR_H
#define __CPAR_H
////////////////////////////////////////////////////////////////////////////////
//
// CPar.h
// <CPar.cpp>
//
// CPar           -   
// SimpleBase     -     
// BaseMacroParam -   
// 
////////////////////////////////////////////////////////////////////////////////
#include "resource.h"

#ifndef  _CPROPMEN_H
#include "cPropMen.h"
#endif

#define LIB_HELP           _T("Gayka.hlp")      //  
#define LIB_LAT            _T("Spc.lat")        //  
#define LIB_VER            02               //  

#define _SHOW_ERRORS         //  -    

//   
#define SPC_FORMAT         1 // 
#define SPC_ZONA           2 // 
#define SPC_POSITION       3 // 
#define SPC_MARKER         4 // 
#define SPC_NAME           5 // 
#define SPC_COUNT          6 // 
#define SPC_NOTE           7 // 

#define BASE_LINE          1 //   
#define SLIM_LINE          2 //  
#define AXIS_LINE          3 //   
#define SHTRIH_LINE        4 //   
#define AXIS_END           3 //       
#define BREAK_LINE        11 //   

//  
#define MIN_H_ANG         -360             //  
#define MAX_H_ANG          360             //  
#define MIN_H_STEP         0.01            //  
#define MAX_H_STEP         100             //  
#define MAX_COUNT_SPCOBJ   4               //      

#define EPSILON            0.001           //       float
#define STANDART_SECTION   25              //     

#define SPCOBJ_CREATE  true                //     
#define COUNT_MASSA        1000   //      
#define WORKWINDOWCOLOR    -1 //     
#define MODSTEP_REAL       0.5412765877 

typedef unsigned char uint8;

struct RequestInfo;
struct HotPointDescription;
struct HotPointDescription1;
////////////////////////////////////////////////////////////////////////////////
//     
// ---
struct SimpleBase 
{
  reference bg;	      //  
  reference rg1, rg2; //  
  SimpleBase() { ::memset( &bg, 0, sizeof(SimpleBase) ); }
};

////////////////////////////////////////////////////////////////////////////////
//   
///
struct BaseMacroParam {
  BYTE version;                //  
  union {
    struct {
      uint8 flagAttr : 1;      //0x01   
      uint8 flagAxis : 1;      //0x02  
      uint8 flagSimp : 1;      //0x04  
    } flags;
    uint8 bitVector;
  };
  short          drawType;     //  
  BaseMacroParam();
};

////////////////////////////////////////////////////////////////////////////////
//
//   
//
////////////////////////////////////////////////////////////////////////////////
class CPar : public PropertyManagerObject {

protected :
  unsigned int   command;    //  
  reference      refMacr;    //  
  reference      spcObject;  //   
  bool           changed;    //   
  //                               
  double         x;
  double         y;
  double         angle;  
  //    
  SimpleBase     base;
  //    . .         
  BaseMacroParam m_baseParam;
  
public:

//   
static __declspec(dllexport) WINAPI CallBackP ( int com, double *x,
                              double *y, double *angl,
                              RequestInfo *info,
                              void *phantom,
                              int dynamic );
//    
static __declspec(dllexport) WINAPI LeaderCallBack( 
                              int com, double *x, double *y, 
                              RequestInfo *info,
                              void *phantom,
                              int   dynamic );
           
           bool Changed()   { return changed; }  //   
           void SetChange() { changed = true; }  //   
           bool DrawSpcObj( reference _group );  //   
           
//           int  GetCommand() { return command; } //  

           //  
           CPar( unsigned int command, reference ref = 0 );
// virtual   CPar*     DublicateObj() { return NULL; }
           //    
// BaseMacroParam&     GetBaseParam() { return m_baseParam; }
           
//*******************   *****************************
  //       
  virtual  void  GetGroup() = 0;                        //   
  virtual  void  SetParam();                            //   -  
  virtual  int   Size() { return sizeof(m_baseParam); } // -   
  virtual  bool  IsSpcObjCreate() { return false; }     //      
  virtual  bool  _EditSpcObj() { return true; }         //   
  virtual  bool  OpenBase()   = 0; //{ return false; }  //  
  virtual  void  CloseBase();//  = 0; //{}                 //  
           void  CloseBase( reference bd ); 
  //        -  
  //          CfgDlg
  virtual  long  GetPromptID()      { return 0;    }   // -       
  virtual  bool  IsSpcGostSection() { return true; }   //      
  //             
  virtual  double AttrNumber() { return 0; } 
  
  //     
  //      -      
  virtual  double    HatchAngle() { return 0; }             //    
  virtual  double    HatchStep()  { return 0; }             //    
  virtual  void      SetHatchAngle( double hatch ) {}       //  
  virtual  void      SetHatchStep ( double step  ) {}       //  
  // (  )
  //           true  
  
  // true -     
  virtual  bool      HatchEnable() { return m_baseParam.drawType == ID_SEC; }
           //   
           void      SetHatchControlEnable( bool enable ); 
 //              
  virtual  void      ShowHatchControl();
 
//******************************************************************************

// HOT_POINTS ##################################################################
  //   Hot 
  /* ILibHPObject */            
  virtual bool GetHotPoints       ( HotPointDescription* point, int index ) { return false; } //   Hot 
  virtual bool SetHotPoint        ( HotPointDescription* point, int index );                   //   Hot 
  virtual bool GetCursorText      ( int index, char** text )                { return false; } //   Hot 
  virtual bool Prepare            ()   { return false; }
  virtual bool ExecuteCommand     ( int id )                                { return true;  } //  
  virtual bool EditComplete       ( int index, BOOL success )               { return true;  } //     ,    
  virtual int  GetMenu            (int index = -1)                          { return 0; }     // 
  virtual bool ChangeHotPointParam( double d )                              { return true;  };//   Hot 

  /* ILibHPObject1 */            
  virtual bool     GetHotPointsEx( HotPointDescription1* point, int index ) { return false; } //   Hot 
//  K10   virtual bool GetViewData     ( HotPointDescription1 * point, int index ) { return false; };
  virtual LPOLESTR GetCursorTextEx ( int index )                               { return NULL; } //   Hot 
  virtual bool     UpdateCommand   ( int id )                                  { return true;  } //     ,   LibHotPnt_GetMenu()  LibHotPnt_GetMenuEx
  virtual bool     SelectHotPoint  ( int index )                               { return false; } 
  virtual bool     UnselectHotPoint( int index )                               { return false; } 
// HOT_POINTS ##################################################################
  
//   ##################################################################
  //      
  // prButtonClick -  .
  virtual bool OnButtonClick( long buttonID );
    
  //prChangeControlValue -   
  virtual bool OnChangeControlValue( /*IPropertyControl* cntrl,*/ long ctrlID, const VARIANT& newVal );
  
  // puCreateOCX - C   
  virtual void OnCreateOCX( long ctrlID, LPDISPATCH control );
    //  
  virtual void RedrawPhantom();  
  
//    //prControlCommand   
//  virtual bool OnControlCommand(LPUNKNOWN  ctrl);

//    //prButtonUpdate        -    .
//  virtual bool OnButtonUpdate(long buttonID, long* check, BOOL* _enable);
          //    
  
  //     
  virtual void       ShowControls();
//   ##################################################################
  
           void      Assign ( const CPar &other );   //  
  operator void* () { return &m_baseParam.version; } //       void*

           void      DrawGroup( reference& gr );     //   
           void      Draw1();                        //   -

  static   void      _MessageBoxResult();
  reference          EditSpcObj( reference _group ); //   
                     //     
  void               SetPlacement( double x, double y, double angle );
  void               DrawPosLeader();
  virtual            GetVersion() { return 1; }      // 
                     //    
  virtual int        _GetMacroParam( void* value, unsigned int size );
  virtual reference  GetPreviewGroup();
  virtual void       RedrawPreview() {}

};

////////////////////////////////////////////////////////////////////////////////
// 
//
bool GetFullName( TCHAR* inName, TCHAR* outName, int outNameLen );
int  _ConnectDB(reference db, TCHAR* name );

//        "." 
// "123.000" -> "123";   "123.10" -> "123.1"
// pointToComma =1  '.'  ','
void CheckDecimelPart( TCHAR *s, unsigned int pointToComma );

extern CPar* NewCParObject( int command, reference ref );
//------------------------------------------------------------------------------
//    
// ---
LPTSTR LoadStr( int id );
void   GetNewKompasAPI();
 
extern AFX_EXTENSION_MODULE StepDLL;
#endif
