Mega Code Archive

 
Categories / Delphi / Graphic
 

MNCadBuilder RapidCAD with Delphi (OpenGL) (part IV)

Title: MNCadBuilder - RapidCAD with Delphi (OpenGL) (part IV) Question: Delphi and 3D CAD development - User Interactivity (Win32 and VCL.NET) Answer: 1. Please make sure you have read the articles "MNCadBuilder - RapidCAD with Delphi", "MNCadBuilder - RapidCAD with Delphi (part II)" and "MNCadBuilder - RapidCAD with Delphi (part III)" to avoid installation or configuration problems. We take the basics from "MNCadBuilder - RapidCAD with Delphi (part III)" and extend our small program with some interactivity. We drag and drop a TMNComponentEditor from the MNEditors page on to the form. Whenever user interactivity is needed the TMNComponentEditor is the right tool (check the help file for more detailled informations). Whenever the user creates a shape, the shape shall be selectable - so we add this shape to the TMNComponentEditor Items list: procedure TForm1.pbCreateClick(Sender: TObject); var B : TBase; aShape : TMyShape; begin // create the shape aShape := TMyShape.Create (NIL); with aShape do begin ... MNParent := MyGroup; MNComponentEditor1.Items.Add (aShape); end; end; Now we want to be informed when the selection changes: The TMNComponentEditor offers an event called OnSelChanged, and this is exactly what we need. procedure TForm1.MNComponentEditor1SelChanged(Sender: TObject); var aShape : TMyShape; begin // whenever the selected item changes, this event is called with Sender as TMNComponentEditor do begin // we want to retrieve the properties of the selected shape If SelItems.Count 0 then begin aShape := SelItems.Objects[0] as TMyShape; edO.Text := XYZToStr (aShape.Base.BaseO); edLSize.Text := DoubleToStr (aShape.LSize); edSSize.Text := DoubleToStr (aShape.SSize); end; end; end; What about updating the properties of the selected shape? No problem, we can use our Edit fields, and implement in the OnKeyUp event to update the selected shape: The property LSize: procedure TForm1.edLSizeKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = 13 then begin Key := 0; // we update the property of the selected shape with MNComponentEditor1 do begin If SelItems.Count 0 then begin with SelItems.Objects[0] as TMyShape do LSize := StrToFloat ((Sender as TEdit).text); end; end; end; end; The property SSize: procedure TForm1.edSSizeKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = 13 then begin Key := 0; // we update the property of the selected shape with MNComponentEditor1 do begin If SelItems.Count 0 then begin with SelItems.Objects[0] as TMyShape do SSize := StrToFloat ((Sender as TEdit).text); end; end; end; end; The Origin of the shape: procedure TForm1.edOKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); VAR B : TBase; begin if Key = 13 then begin Key := 0; // we update the property of the selected shape with MNComponentEditor1 do begin If SelItems.Count 0 then begin with SelItems.Objects[0] as TMyShape do begin // because we can not change Shape.Base.BaseO := ... // we have to use a local variable B := Base; B.BaseO := StrToXYZ ((Sender as TEdit).text); Base := B; end; end; end; end; end; These were the first steps of the MNCadBuilder's interactivity features. Here you will find the source (Win32). Leopold Minikus DeveloCAD.com