unit Base;
////////////////////////////////////////////////////////////////////////////////
//
// CPar.h
// <CPar.cpp>
//
// CPar           -   
// SimpleBase     -     
// BaseMacroParam -   
//
////////////////////////////////////////////////////////////////////////////////

interface
 uses  Windows,  Sysutils, LtDefine, LibTool, LibDB, LDefin2D, forms, controls,
       classes, LibHpPar, ManagerEvents, GaykaRC,
{$IFDEF __LIGHT_VERSION__}
  klAPI7;
{$ELSE}
  ksApi7;
{$ENDIF}

type



////////////////////////////////////////////////////////////////////////////////
//     
// ---
SimpleBase = record
  bg       : reference;	//  
  rg1, rg2 : reference; //  
end;

BaseMakroParam  = packed record
  version  : Byte;     // 
  drawType : smallInt; //  
  flags    : Byte;     // 
  {
    BOOL attr      : 1;   //   
    BOOL simple    : 1;   // 
    BOOL axis      : 1;   //  
    BOOL dimension : 1;   //  
  }

end;

//   
PCPar = ^CPar;
CPar  = class ( PropertyManagerObject )
protected
  m_command   : integer;    //  
  m_refMacr   : reference;  //  
  m_spcObject : reference;  //   

  //    
  m_x, m_y, m_angle : Double;
  //    
  m_base      : SimpleBase;
  //      
  m_baseParam : BaseMakroParam;

public

  constructor Create( comm     : integer; ref : reference ); // 
  procedure   Assign( other    : CPar );  virtual;           //  

// HOT_POINTS ##################################################################
  //   Hot 
  function GetHotPoints(  point : PHotPointDescription; index : Integer ) : LongBool; virtual; //   Hot 
  function SetHotPoint (  point : PHotPointDescription; index : Integer ) : LongBool; virtual; //   Hot 
  function GetCursorText( index : Integer;          Var text  : PChar   ) : LongBool; virtual; //   Hot 
  function EditComplete(  index : Integer;            success : LongBool) : LongBool; virtual; //     ,    
// HOT_POINTS ##################################################################

  procedure  Draw1;
  function   DrawSpcObj( group : reference ) : Boolean;      //    

protected
  function    GetCParSize      : Integer;                    // -   
  function    GetSize          : Integer; virtual;                   // -   
//  :
  function    GetVersion       : Integer; virtual;           //   

//  function   GetChanged        : Boolean;                    //    
//  procedure  SetChanged;

  //     BaseMakroParam
  function   GetAttr           : Boolean;                    //   
  procedure  SetAttr     ( val : Boolean );

  function   GetSimple         : Boolean;                    // 
  procedure  SetSimple   ( val : Boolean );

  function   GetAxis           : Boolean;                    //  
  procedure  SetAxis     ( val : Boolean );

  function   GetDimension      : Boolean;                    //  
  procedure  SetDimension( val : Boolean );

//  function   GetDrawType      : smallInt;                    //  
//  procedure  SetDrawType( tip : smallInt );

  //  
  function   GetHatchAngle        : Double;   virtual;       //  
  function   GetHatchStep         : Double;   virtual;       //  
  procedure  SetHatchAngle( hatch : Double ); virtual;       //  
  procedure  SetHatchStep(  step  : Double ); virtual;       //  

  function   GetHatchEnable: Boolean;         virtual;       //      

  function   GetMassa  : Double;             virtual;        // 

public
  property  Size       : Integer  read GetSize;


  property  Attr       : Boolean  read GetAttr              write SetAttr;
  property  Simple     : Boolean  read GetSimple            write SetSimple;
  property  Axis       : Boolean  read GetAxis              write SetAxis;
  property  Dimension  : Boolean  read GetDimension         write SetDimension;
  property  DrawType   : SmallInt read m_baseParam.drawType write m_baseParam.drawType;
  property  Massa      : Double   read GetMassa;

  property  HatchEnable: Boolean  read GetHatchEnable;
  property  HatchAngle : Double   read GetHatchAngle        write SetHatchAngle;
  property  HatchStep  : Double   read GetHatchStep         write SetHatchStep;

protected
//*******************   *****************************
  //       
  procedure GetGroup       ;            virtual;             //   
  procedure SetParam       ;            virtual;             //   -  
  function  OpenBase       : Boolean;   virtual;             //  
  procedure CloseBase      ;            virtual;             //  
  procedure _CloseBase( bd : reference );                    //  
  function  AttrNumber     : Double;    virtual;             //  
  function  IsSpcObjCreate : Boolean;   virtual;             //      
  function  _EditSpcObj    : Boolean;   virtual;             //   
  function  GetPromptID    : Integer;   virtual;
//*******************   *****************************
public
//   ##################################################################
  // 
  // prButtonClick -  .
  procedure OnButtonClick( buttonID : Integer ); override;

  //prChangeControlValue -   
  procedure OnChangeControlValue( {var cntrl : IPropertyControl,} ctrlID : LongInt; const Val: Variant ); override;

  // puCreateOCX - C   
  procedure  OnCreateOCX( ctrlID : LongInt; var control : IDispatch ); override;
    //  
  procedure  RedrawPhantom(); override;

//    //prControlCommand   
// function OnControlCommand(var ctrl : IUncnown );  override;

//    //prButtonUpdate        -    .
// function OnButtonUpdate(long buttonID, long* check, BOOL* _enable);  override;
          //   

  //     
  procedure ShowControls;  override;

  //      
  procedure ShowHatchControl;  override;

  //     
  procedure SetHatchControlEnable( enable : Boolean );

//   ##################################################################
protected
  function   GetAddr          : pointer;                    //    
  procedure  DrawGroup( var gr : Reference );                //   
  procedure  DrawPosLeader;
  procedure  SetPlacement( x, y, angl : Double );
  function   EditSpcObj( _group : reference ) : reference;   //   
  function   GetPreviewGroup    : reference;              override;
  procedure  RedrawPreview;                               virtual;

end;

//   
procedure SetBitFlag( var flags, mask : byte; fSet : boolean );

//   
function  CallBackP( _dynamic : integer; phantom : pointer; info : PRequestInfo;
                     var angl : double;  var y, x : double;  com : integer ) : integer;  pascal ;

//    
function  LeaderCallBack( _dynamic : integer;phantom : pointer; info : PRequestInfo;
                      var y,x : double; com : integer) : integer;  pascal ;

procedure _MessageBoxResult;
function  LoadStr_( id: Integer ): string;
procedure CheckDecimelPart(s : PChar; pointToComma : Byte);
function  GetFullName(  name : PChar; fName:PChar  ): integer;
function  _ConnectDB(bd : reference; name : PChar ): integer;

// procedure ConvertComponentLang( component: TComponent ); //   

implementation
  uses
    ksConstTLB;

var
  obj     : PCPar   = nil;
  rub     : Phantom;
  fRepeat : boolean = false;     //      
                                 // Placement  Cursor
  oldPosLeader : reference = 0;
  posLeater    : reference = 0; // 0 -   , -1 -    

//------------------------------------------------------------------------------
// 
//---
constructor CPar.Create( comm : integer; ref : reference );
begin
  m_flagMode  := false;    //   
  //    
  m_x         := 0;
  m_y         := 0;
  m_angle     := 0;

  m_spcObject := 0;  //   

  //    
  FillChar( m_base, sizeof(m_base), 0 );
  //      
  FillChar( m_baseParam, sizeof(m_baseParam), 0 );

  with m_baseParam do
  begin
    version  := 1;
    flags    := 0;
    drawType := ID_VIEW;
  end;
  m_refMacr            := ref;
  m_command            := comm;
  if m_refMacr <> 0 then
    GetMacroPlacement( m_refMacr, m_x, m_y, m_angle )
  else begin
  end
end;

//------------------------------------------------------------------------------
//
//---
function CPar.GetAddr: pointer;
begin
  result := Addr(m_baseParam);
end;

//------------------------------------------------------------------------------
//  
//---
procedure CPar.Assign( other : CPar );
begin
  m_command   := other.m_command;
  m_refMacr   := other.m_refMacr;
  m_flagMode  := other.m_flagMode;
  m_angle     := other.m_angle;
  m_baseParam := other.m_baseParam;
end;

//------------------------------------------------------------------------------
//
//---
function CPar.GetCParSize: integer;
begin
  result := SizeOf(m_baseParam);
end;

//------------------------------------------------------------------------------
//
//---
function CPar.GetSize: integer;
begin
  result := GetCParSize;
end;

//------------------------------------------------------------------------------
//
//---
function CPar.GetHatchAngle : Double;
begin
  Result := 0;
end;

//------------------------------------------------------------------------------
//
//---
procedure CPar.SetHatchAngle( hatch : Double );
begin
end;

//------------------------------------------------------------------------------
//
//---
function CPar.GetHatchStep : Double;
begin
  Result := 0;
end;

//------------------------------------------------------------------------------
//
//---
procedure CPar.SetHatchStep(  step  : Double );
begin
end;

//------------------------------------------------------------------------------
//      
//---
function CPar.GetHatchEnable: Boolean;
begin
  Result := DrawType = ID_SEC;
end;

//------------------------------------------------------------------------------
//     
//---
procedure SetBitFlag( var flags, mask : byte; fSet : boolean );
begin
  if fSet then
    flags := flags or mask
  else
    flags := flags or mask xor mask;
end;

//------------------------------------------------------------------------------
// 
//---
procedure CPar.SetSimple( val : Boolean );
begin
  SetBitFlag( m_baseParam.flags, BF_SIMPLE, val );
end;

//------------------------------------------------------------------------------
// 
//---
function CPar.GetSimple : Boolean;
begin
  Result := ( m_baseParam.flags and BF_SIMPLE ) <> 0;
end;

//------------------------------------------------------------------------------
// 
//---
function  CPar.GetAttr : Boolean;
begin
  Result := ( m_baseParam.flags and BF_ATTR ) <> 0;
end;

//------------------------------------------------------------------------------
//   
//---
procedure CPar.SetAttr( val : boolean );
begin
  SetBitFlag( m_baseParam.flags, BF_ATTR, val );
end;

//------------------------------------------------------------------------------
// 
//---
function CPar.GetAxis : boolean;
begin
  Result := ( m_baseParam.flags and BF_AXIS ) <> 0;
end;

//------------------------------------------------------------------------------
// 
//---
procedure CPar.SetAxis( val : boolean );
begin
  SetBitFlag( m_baseParam.flags, BF_AXIS, val );
end;

//------------------------------------------------------------------------------
// 
//---
function CPar.GetDimension : boolean;
begin
  Result := ( m_baseParam.flags and BF_DIMENSION ) <> 0;
end;

//------------------------------------------------------------------------------
// 
//---
procedure CPar.SetDimension( val : boolean);
begin
  SetBitFlag( m_baseParam.flags, BF_DIMENSION, val );
end;

//------------------------------------------------------------------------------
// 
//---
function CPar.GetMassa : Double;
begin
  Result := 0;
end;
{
//------------------------------------------------------------------------------
//
//---
function  CPar.GetDrawType: smallInt;
begin
  GetDrawType := m_baseParam.drawType;
end;

//------------------------------------------------------------------------------
//
//---
procedure  CPar.SetDrawType( tip : smallInt );
begin
  m_baseParam.drawType := tip;
end;
}

//------------------------------------------------------------------------------
//   
//---
function CPar.EditSpcObj( _group : reference ) : reference;
var
  massaTmp : Double;
  buf      : string;

begin
  m_spcObject := 0;
  if m_flagMode then begin
    m_spcObject := ksGetSpcObjForGeomWithLimit( nil,              //   
                                                0,                //   
                                                _group,
                                                0,                // 1 -      ; 0-    
                                                1,                // 1 -  0-  
                                                STANDART_SECTION, // GetElementSpcSection //  
                                                AttrNumber
                                              );
    if not Attr then begin
      Result := 0;
      Exit;
    end;

    if ( ( m_spcObject <> 0 ) and ( ksSpcObjectEdit(m_spcObject) = 0 ) ) then //   
      m_spcObject := 0;

  end;

  //  
  if ( m_spcObject or
       ksSpcObjectCreate( nil,                               //   
                          0,                                 //   
                          STANDART_SECTION,
                          0,                                 // GetElementSpcSection //     
                          AttrNumber,
                          0) <> 0 ) then begin                //  

    _EditSpcObj();                                           //   

    massaTmp := Massa;

    if massaTmp > 1e-5 then  begin
      buf := Format( '%g', [Massa] );
      ksSpcMassa(    PChar(buf)    );                          //  
    end;

    if _group <> 0 then                                      //  
      ksSpcIncludeReference( _group, 1 );

    m_spcObject := ksSpcObjectEnd();                         //   
  end;
  Result := m_spcObject;
end;

//------------------------------------------------------------------------------
//     
//---
procedure CPar.Draw1;
var
  j    : integer;         //   
  info : RequestInfo;     //  
begin
  j               := 1;
  //  
  FillChar( rub, sizeof(rub), 0 );
  rub.type1.scale := 1;              // 
  rub.phType      := 1;              //  - 

  if ( ReturnResult = 0 ) then       //  
  begin
    m_flagMode := EditMacroMode > 0; // - m   
    obj := Addr(self);               //   
    if OpenBase then                 //  
    begin
      //   
      if ( InitProcessParam( m_command + 4000,  m_command + 4000, pnEnterEscHelp ) ) then
      begin
        while ( j<>0 ) do
        begin
          fRepeat := false;
          DrawGroup( rub.type1.gr );                        //  
          rub.type1.ang := m_angle;                         //   

          //  
          FillChar(info, sizeof(info), 0 );
          info.commands := PChar( GetPromptID() );          // 
          info._dynamic := 1;                               // 1 -  
          info.callBack := Addr(CallBackP);                 //   

          //   
          j := PlacementEx( Addr(info), m_x, m_y, m_angle, Addr(rub), PIUnknown(procParam) );

          //   
          if Attr and ( m_spcObject <> 0 ) then begin
            if ksEditWindowSpcObject( m_spcObject ) <> 0 then
              DrawPosLeader();                 //   
            m_spcObject := 0;
          end;

          if m_flagMode then
            j := 0
          else
            if fRepeat then begin         //    
              j := 1;
              DrawGroup( rub.type1.gr );  //   
            end;
        end;
      end;
      EndProcess;                         //  
      CloseBase();                        //  
    end;
  end;
end;

//------------------------------------------------------------------------------
//      
//---
function CallBackP( _dynamic : Integer;                      //   
                    phantom  : Pointer;                      // 
                    info     : PRequestInfo;                 //  
                    var angl, y, x : Double;                 //  
                    com      : integer ) : Integer; pascal ; //  
var
  rub : PPhantom;
begin

  rub := PPhantom (phantom);
  if( _dynamic = 0 ) then                               // 
  begin
    case ( com ) of
      -1 : begin                                        //   
//        obj^.angle := angl;
        obj^.SetParam();                                //  
        obj^.SetPlacement( x, y, angl );                // 
        StoreTmpGroup( rub^.type1.gr );                 //  
        fRepeat := obj^.DrawSpcObj( rub^.type1.gr );
        ClearGroup( rub^.type1.gr );                    //  
        if ( fRepeat or obj^.m_flagMode ) then          //   
        begin
          result  := 0;                                 //   
          exit;
        end;
      end;
    end;

    obj^.DrawGroup ( rub^.type1.gr );                   //  
  end;
//  else begin
//    obj^.angle := angl;
//    obj^.RedrawPahtom;
//  end;
  result := 1;
end;

//------------------------------------------------------------------------------
//  
//---
procedure CPar.DrawGroup( var gr : reference );
begin
  if ExistObj(gr) <> 0 then  //    
    DeleteObj(gr);           //  

  gr := NewGroup( 1{  } ); //   
    m_refMacr := 0;
    Macro(0);

    GetGroup;                                //  -
    m_refMacr := EndObj();

  EndGroup();                                //  
  _MessageBoxResult();
  changed := false;
end;

//------------------------------------------------------------------------------
//  , ,   
//---
procedure CPar.RedrawPhantom;
var
  gr : reference;
begin
  if Changed then
  begin
    DrawGroup( rub.type1.gr );
    ksChangeObjectInLibRequest( nil, Addr(rub) );

    //  
    if paramGrid <> nil then
    begin
      rowIndex := 1;                   //    
      ShowParam();                     //  
      paramGrid.RowCount := rowIndex;  //    
      paramGrid.UpdateParam();         //  
    end;

    //    
    if slideBox <> nil then
    begin
      //   
      gr := LongInt( slideBox.DrawingSlide );
      if gr <> 0 then
        DeleteObj( gr );
      //  
      gr := GetPreviewGroup();
      slideBox.DrawingSlide := gr;
      slideBox.UpdateParam;      // 
    end
  end
end;


//------------------------------------------------------------------------------
//    
//---
function LeaderCallBack ( _dynamic : integer;phantom : pointer; info : PRequestInfo;
                      var y,x : double; com : integer) : integer;  pascal;
var
  newPosLeater : reference;
begin
  if ( posLeater <> -1 ) then begin

    //      
    newPosLeater := FindObj( x, y, ksGetCursorLimit ); //   -   x,y
    //     -     
    if ( newPosLeater <> 0) and ( GetObjParam(newPosLeater, nil, 0, ALLPARAM) <> POSLEADER_OBJ )  then
      newPosLeater := 0;                        //     

    if _dynamic = 0 then                       //  
    begin
      if newPosLeater = 0 then
        Error( PChar(LoadStr(ID_ERROR_LEADER)) )       //   
      else begin                                //    
        posLeater := newPosLeater;              //     

        if oldPosLeader <> 0 then
          LightObj( oldPosLeader, 0 );          //      

        Result := 0;                            //  
        Exit;
      end

    end
    else begin
      //     
      if newPosLeater <> oldPosLeader then begin
        if oldPosLeader <> 0 then
          LightObj( oldPosLeader, 0 );          //      

        oldPosLeader := newPosLeater;

        if oldPosLeader <> 0 then
          LightObj( oldPosLeader, 1 );          //    
      end
    end;
  end;
  result := 1;
end;

//-------------------------------------------------------------------------------
//    
//     Cursor  Placement
// ---
procedure CPar.DrawPosLeader;
var
  info : RequestInfo;
  x, y : Double;
  comm : Integer;
begin
  oldPosLeader := 0;
  posLeater    := 0;

  if IsSpcObjCreate and InitPosLeaderParam then
  begin
    FillChar( info, sizeof(info), 0 );
    info.prompt   := PChar(ID_INDICATE_LEADER);
    info._dynamic := 1;
    info.callBack := Addr(LeaderCallBack);          //   
    comm := ksCursorEx( Addr(info), x, y, nil, PIUnknown(posLiaderParam) );
    if ( comm <> 0 ) and ( oldPosLeader > 0 ) then
      LightObj( oldPosLeader, 0 );          //        (Esc)
  end;

  if posLeater < 0 then
    posLeater := ksCreateViewObject( POSLEADER_OBJ );

  //   ,     
  if posLeater > 0 then
  begin
    //      
    if ksSpcObjectEdit( m_spcObject ) <> 0 then
    begin
      //   
      ksSpcIncludeReference( posLeater, 1 );
      //   
      ksSpcObjectEnd();
    end
  end;
  posLeater := 0;
end;

//-------------------------------------------------------------------------------------
//  
//---
function CPar.GetPreviewGroup: Reference;
begin
  Result := NewGroup( 1 ); //   
    GetGroup();
  EndGroup();            //  
end;

//------------------------------------------------------------------------------
//   
// ---
procedure CPar.SetPlacement( x, y, angl : Double );
begin
  if m_refMacr <> 0 then
    SetMacroPlacement( m_refMacr, x, y, angl, 0 );
end;

//------------------------------------------------------------------------------
//   
//---
function CPar.DrawSpcObj( group : reference  ): boolean;
begin
  m_spcObject := 0;
  if Attr and IsSpcObjCreate then
  begin
    if ReturnResult = etError10 then    //  10  "!  "
      ResultNULL();

    m_spcObject := EditSpcObj( group );
  end;
  result := m_spcObject <> 0;
end;

// HOT_POINTS ##################################################################
//   Hot 

//------------------------------------------------------------------------------
//   Hot 
//---
function CPar.GetHotPoints( point : PHotPointDescription; index : integer ) : LongBool;
begin
  Result := false;
end;

//------------------------------------------------------------------------------
//     
//---
function CPar.SetHotPoint( point : PHotPointDescription; index : integer ) : LongBool;
var
  ang : Double;
begin
  case index of
    0 : SetPlacement( point^.x, point^.y, 0.0 ); //  
    1 : //  
      begin
        ang := Angle( 0, 0, point^.x, point^.y );
        SetPlacement( 0, 0, ang );
      end;
  end;
  Result := index < 2;
end;

//------------------------------------------------------------------------------
//   Hot 
//---
function CPar.GetCursorText( index : Integer; var text : PChar ) : LongBool;
begin
  Result := false;
end;

//------------------------------------------------------------------------------
//     ,    
//---
function CPar.EditComplete( index : Integer; success : LongBool ) : LongBool;
begin
  Result := true;
end;

//------------------------------------------------------------------------------
// 
//---
function CPar.GetVersion : Integer;
begin
  result := 1;
end;

// HOT_POINTS ##################################################################

//------------------------------------------------------------------------------
//  
//---
function CPar.OpenBase : Boolean;
begin
  Result := false;
end;

//------------------------------------------------------------------------------
//  
//---
procedure CPar._CloseBase( bd : reference );
begin
  DeleteDB( bd );
end;

//------------------------------------------------------------------------------
//  
//---
procedure CPar.CloseBase;
begin
  if m_base.bg <> 0 then
    _CloseBase( m_base.bg );
end;

//------------------------------------------------------------------------------
//  
//---
function CPar.AttrNumber : Double;
begin
  Result := 0;
end;

//------------------------------------------------------------------------------
//      
//---
function CPar.IsSpcObjCreate : Boolean;
begin
  Result := false;
end;

//------------------------------------------------------------------------------
//   
//---
function CPar._EditSpcObj : Boolean;
begin
  Result := true;
end;

//------------------------------------------------------------------------------
//   
//---
function CPar.GetPromptID: Integer;
begin
  Result := 0;
end;

//------------------------------------------------------------------------------
//   
//---
procedure CPar.RedrawPreview;
begin
end;

//   ############################################################
//-------------------------------------------------------------------------------
//   
// ---
procedure CPar.ShowControls;
var
  checkBox : IPropertyCheckBox;
begin
  if IsSpcObjCreate then
  begin
    checkBox := CreateCheckBox( Attr ) As IPropertyCheckBox;
    if checkBox <> nil then
      InitPropertyControl( IPropertyControl(checkBox), IDP_SPC_OBJ, IDS_SPC_OBJ_TIPS, IDS_SPC_OBJ_TIPS, ksNameAlwaysVisible, true, true );
  end
end;


procedure CPar.ShowHatchControl;
begin
  if IsHatchObject then
  begin
//    CreateTab( IDP_HATCH_PAGE );
//    CreateSeparator( 0, ksSeparatorDownName );

    CreateUserControl( IDP_HATCH_PARAM, 100, 150 );
//    CreateRealEdit( IDP_HATCHANG_ANGLE, HatchAngle, -360, 360, HatchEnable );
//    CreateRealEdit( IDP_HATCHANG_STEP, HatchStep, 0.01, 100, HatchEnable );
  end
end;

procedure CPar.SetHatchControlEnable( enable : Boolean );
begin
  if hatchCtrl <> nil then
  begin
//    SetControlEnable( IDP_HATCH_PARAM,  enable );
    hatchCtrl.Enable := enable;
  end
end;

//-------------------------------------------------------------------------------
//   ActiveX Control-a
// ---
procedure CPar.OnCreateOCX( ctrlID : LongInt; var control : IDispatch );
begin
  if ctrlID = IDP_HATCH_PARAM then
  begin
    hatchCtrl := control As _DVCHatch;
    if hatchCtrl <> nil then
    begin
      hatchCtrl.Angle := HatchAngle;
      hatchCtrl.Step  := HatchStep;
      SetHatchControlEnable( HatchEnable );
    end;
  end;
end;

procedure CPar.OnChangeControlValue( {var cntrl : IPropertyControl;} ctrlID : LongInt; const val : VARIANT );
begin
  case ctrlID of
{
   case IDP_HATCHANG_ANGLE:
      SetHatchAngle( newVal.dblVal );
      changed = true;
      break;
    case IDP_HATCHANG_STEP:
      SetHatchStep( newVal.dblVal );
      changed = true;
      break;
}

    IDP_SPC_OBJ:
      Attr :=  not Attr;

  end;
end;

//----------------------------------------------------------------------------------------------------
//   
// ---
procedure CPar.GetGroup;
begin
end;

//----------------------------------------------------------------------------------------------------
//   -  
// ---
procedure CPar.SetParam;
begin
end;

//----------------------------------------------------------------------------------------------------
//   
// ---
procedure CPar.OnButtonClick( buttonID : LongInt );
var
  oldSec : Boolean;
begin
  oldSec := HatchEnable; //   
  case buttonID of
    // 
    ID_VIEW,     // 
    ID_LEFT,     // C
    ID_TOP,      // C
    ID_SEC:      // /
      begin
        DrawType := buttonID;
        Changed  := true;
      end;

    ID_SIMPLE: // 
      begin
        Simple  := not Simple;
        Changed := true;
      end;

    ID_AXIS: //  
      begin
        Axis     :=  not Axis;
        Changed  := true;
      end;

    ID_LEADER_CREATE: //    
      begin
        if newKompasAPI <> nil then
        begin
          newKompasAPI.StopCurrentProcess( TRUE, nil );
          posLeater := -1;
        end;
      end;
  end;

  if Changed then
  begin
    //      
    if oldSec <> HatchEnable then
    begin
      SetHatchControlEnable( HatchEnable );
//      SetControlEnable( IDP_HATCHANG_ANGLE,  m_baseParam.drawType == ID_SEC );
//      SetControlEnable( IDP_HATCHANG_STEP,   m_baseParam.drawType == ID_SEC );
    end;
  end;

end;


//   ############################################################

//------------------------------------------------------------------------------
//    
//---
procedure _MessageBoxResult;
begin
  if ( ReturnResult<>0 ) then
  begin
    if ( ReturnResult = etError10 ) then   //  10  "!  "
      ResultNULL()
    else
      MessageBoxResult();
  end;
end;

//--------------------------------------------------------------------------
//        "." 
// "123.000" -> "123";   "123.10" -> "123.1"
// pointToComma =1  '.'  ','
//--------------------------------------------------------------------------
procedure CheckDecimelPart(s : PChar; pointToComma : Byte);
var
  pos  : integer;
  flag : boolean;
  i    : integer;
    //--------------------------------------------------------------------------
    function strchr ( s: PCHar; c : char ) : integer;
    var
      i   : integer;
    begin
      for i:=0 to strlen( s )-1 do
      begin
        if ( s[i] = c ) then
        begin
          result := i;
          exit;
        end;
      end;
      result := -1;
    end;
    //--------------------------------------------------------------------------
begin
  if( s<>nil) And (strlen(s)<>0 ) then
  begin
    pos := strchr( s, '.');
    flag := false;
    if ( pos<>-1 ) then
    begin
      i:=pos;
      inc(i);
      while( s[i] <> '0') And (flag=false ) do
      begin
        if ( s[i] <> '0' ) then
          flag := true;
        inc(i);
      end;
      if( flag=false )then
        s[pos] := char(0)
      else
      begin
        i :=  strlen(s)-1;
        while( s[i]='0' ) do
        begin
          s[i] := char(0);
          dec(i);
        end;
        if ( pointToComma<>0 ) then
          s[pos] := ',';
      end;
    end;
  end;
end;

//------------------------------------------------------------------------------
//    
//---
function GetFullName( name : PChar;  fName : PChar ): integer;
type
OFSTRUCT = record
   cBytes : byte;
   fFixedDisk:byte;
   nErrCode: word;
   Reserved1:word;
   Reserved2:word;
   szPathName: array [0..255] of char;
end;

var
  //pos : integer;
  ofs : TOFSTRUCT;
  c   : PChar;
begin
  if( GetModuleFileName( HInstance, fName, 255)<>0 ) then
  begin
    c := strrscan( fName, '\');
    if ( c<>nil ) then
    begin
      StrCopy( c+1, '');
      strcat ( fName, name );
      if ( OpenFile(fName , ofs, OF_EXIST) <> HFILE_ERROR )then
      begin
        result:= 1;
        exit;
      end
      else begin
        StrCopy( c+1, '');
        strcat ( fName, 'LOAD\' );
        strcat ( fName, name );
        if ( OpenFile(fName , ofs, OF_EXIST) <> HFILE_ERROR )then
        begin
          result:= 1;
          exit;
        end;
      end;
    end;
  end;
  result := 0;
end;

//------------------------------------------------------------------------------
//
//---
function _ConnectDB(bd : reference; name: PChar ): integer;
var
  buf : array[0..255] of char;
begin
  if ( GetFullName( name, buf  )=1 ) then
    result := ConnectDB( bd, buf )
  else
    result := ConnectDB( bd, name );
end;

//------------------------------------------------------------------------------
//
//---
function _GetMacroParam( value : pointer;  size : cardinal ): integer;
begin
  result := GetMacroParam( 0, value, size);
end;

{
//------------------------------------------------------------------------------
//   
//---
procedure ConvertLangForm( form : TForm );

var
  I: Integer;

  procedure ConvertLangControl( opControl : TOpenControl );
    var
    buf     : array[0..MAX_TEXT_LENGTH] of Char; // 
  begin
    if ( ksConvertLangStr( PChar(opControl.caption), buf, MAX_TEXT_LENGTH ) <> 0  ) Then
      opControl.caption := buf;
    if ( ksConvertLangStr( PChar(opControl.hint), buf, MAX_TEXT_LENGTH ) <> 0  ) Then
      opControl.hint := buf;
    if ( ksConvertLangStr( PChar(opControl.text), buf, MAX_TEXT_LENGTH ) <> 0  ) Then
      opControl.text := buf;
  end;

begin
  for I:= 0 to form.ControlCount -1 do
  begin
    if ( form.Components[I] is TControl ) then
      ConvertLangControl( TOpenControl(form.Components[I] as TControl) );
  end;
  //     
  ksConvertLangWindow( form.Handle );
end;
}

//------------------------------------------------------------------------------
//    
//-
function LoadStr_( id: Integer ): string;
var
//  buf:    string;
  bufRes: array[0..MAX_TEXT_LENGTH] of Char;
begin
//  buf := LoadStr( id );
  ksConvertLangStrEx( hInstance, id, bufRes, MAX_TEXT_LENGTH );// <> 0 then
  result := bufRes
//  else
//    result := buf;
end;
{
//------------------------------------------------------------------------------
//   
//-
procedure ConvertComponentLang( component: TComponent );
var
  control: TControl;
  buf: array[0..MAX_TEXT_LENGTH] of AnsiChar;
  i: Integer;

begin
  if component <> nil then
  begin
    if component is TControl then
    begin
      control := component as TControl;

      if ksConvertLangStr( PChar(control.Hint), buf, SizeOf(buf)) <> 0 then
        control.Hint := buf;

      control.GetTextBuf( buf, SizeOf(buf) );

      if ksConvertLangStr(buf, buf, SizeOf(buf)) <> 0 then
        control.SetTextBuf( buf );
    end;

    if component.ComponentCount > 0 then
      for i := 0 to component.ComponentCount - 1 do
        ConvertComponentLang( component.Components[i] );
  end;
end;
}


end.


