Code sample Home

Retrieve position on a curve of "road plan" object by mouse click.

The below function is called on the Left button down event.
When user clicks on RPlan object, the function find coordinates on the curve and insert a point on this place.

void DemoRPlanLBDown (HANDLE hEvent)
{
  HANDLE hLcWnd, hDrw, hBlock, hPtStyle, hRPlan, hPnt;
  int    EntType;
  double X, Y, X2, Y2, Dist, Offset;
  WCHAR* szName = L"MyPtStyle";

  //------- This part is used to set style and color for new points
  // get drawing handle
  hDrw = lcPropGetHandle( hEvent, LC_PROP_EVENT_DRW );
  // set active point style
  hPtStyle = lcDrwGetObjectByName( hDrw, LC_OBJ_PNTSTYLE, szName );
  if (hPtStyle == 0){
    // the point style don't exist, create it
    hPtStyle = lcDrwAddPntStyle( hDrw, szName, 0, 1.0, 0, 1.0, 1.0 );
    lcPropPutInt( hPtStyle, LC_PROP_PSTYLE_PTMODE, LC_POINT_PLUS|LC_POINT_CIRCLE );
    lcPropPutFloat( hPtStyle, LC_PROP_PSTYLE_PTSIZE, -1.0 );
  }
  // set active point style
  lcPropPutHandle( hDrw, LC_PROP_DRW_PNTSTYLE, hPtStyle );
  // set active color
  lcPropPutInt( hDrw, LC_PROP_DRW_COLOR, RGB(255,100,0) );
  //-------------------------

  // get window handle
  hLcWnd = lcPropGetHandle( hEvent, LC_PROP_EVENT_WND );
  // get block handle
  hBlock = lcPropGetHandle( hEvent, LC_PROP_EVENT_BLOCK );
  // get entity by cursor position
  hRPlan = lcWndGetEntByPoint( hLcWnd, -1, -1 );
  if (hRPlan != 0){
    // check the entity type
    EntType = lcPropGetInt( hRPlan, LC_PROP_ENT_TYPE );
    if (EntType == LC_ENT_RPLAN){
      // get cursor coordinates
      X = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT1 );
      Y = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT2 );
      // by the click point, get position on RPlan curve
      if (lcRPlanGetDist( hRPlan, X, Y, &X2, &Y2, &Dist, &Offset )){
        // at found position, add point entity
        hPnt = lcBlockAddPoint( hBlock, X2, Y2 );
        lcBlockUpdate( hBlock, false, hPnt );
        lcWndRedraw( hLcWnd ); 
        // disable default Litecad reaction on the event
        lcEventReturnCode( 1 );
      }
    }
  }
}

See Also:

Create "road plan" object