Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Hilfe, bei Parametrisieren (https://www.delphipraxis.net/184343-hilfe-bei-parametrisieren.html)

Chris211183 19. Mär 2015 09:04

Hilfe, bei Parametrisieren
 
Hallo Ihr Lieben,

ich benötige nochmal eure Hilfe, um endlich mit meinem Histographen abschließen zu können.

Wie mache ich das jetzt, dass er innerhalb meines Anzeigebereichs, von links nach rechts und immer, in der Mitte der Y-Achse, einen Datensatz, den er Extern bekommt, als Sinus anzeigt ???

Delphi-Quellcode:
function mysin(const X: Extended):Extended;                                    // Wrapper-Funktion, benötigt für Delphi 6 um Sinus-Funktion implementieren zu können
begin
   Result := sin(x);
end;



function THixHistoGraph.CalculatePointView                                     // Berechnung der Punkte für die Funktionsdarstellung
(AFunc: TFxFunction; const ARect: TRect; x0, y0, dx, dy: Extended): TPointDynArray;
var
  x, y: Extended;
  i : integer;
begin                                                                          // für jede Spalte einen Punkt
   SetLength(Result, ARect.Right - ARect.Left +1);                             // Punkte berechnen
   x := 0;
   for i := Low(Result) to High(Result) do
   begin
   y := AFunc(x);
   y := -y;                                                                    // Canvas Nullpunkt obere linke Ecke mit Y- Achse nach unten !!!
   y := y0 + y;                                                                // oberen Rand Addieren
   y := y / dy;                                                                // Skalieren
   Result[i].x := ARect.Left +1;
   Result[i].Y := ARect.Top + Round(y) + Round(y);                             // runden
   x := x + dx;
   end;                                                                        // nächster Punkt

end;


////////////////////////////////////////////////////////////////////////////////
//                                                                            //
//                                Zeichnen                                   //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////

procedure THixHistoGraph.DrawComponent;
var
   ComponentBackround         : TRect;                                        // zeichnet Komponente
   HistoBackround             : TRect;                                        // zeichnet die Darstellungsfläche der Komponente
   P                          : TPointDynArray;
   X0, Y0, dx, dy             :Real;
begin

 if FBorderstyle = bsSingle then                                               // mit 3D-Rahmen

   begin
   inherited;
   if (Parent = NIL) or not visible
   then Exit;

   begin
      ComponentBackround := Rect(0, 0, Width, Height);                        // Koponentenhintergrund
   end;
   Canvas.Brush.Color := FColor;
   Canvas.Pen.Color  := FColor;
   Canvas.Pen.Style  := psSolid;
   Canvas.FillRect(ComponentBackround);
   Frame3D(Canvas, ComponentBackround, clBtnHighlight, clBtnShadow, 1);        // 3D Rahmen mit der Breite von 1 für Komponentenhintergrund

   begin
      HistoBackround := Rect(FGapLeft,                                        // Hintergrund der Darstellungsfläche
                              FGapTop,
                              Width - FGapRight,
                              Height - FGapBottom + 2);
   end;
   Canvas.Brush.Color := FHistoBkColor;
   Canvas.Pen.Color  := FHistoBkColor;
   Canvas.FillRect(HistoBackround);
   Frame3D(Canvas, HistoBackround, clBtnShadow, clBtnHighlight, 1);

   begin                                                                       // Zeichnet Messdaten
      InflateRect(HistoBackround, -1, -1);                                     // Darstellung im Hinergrund ohne Ränder
      X0 := 0;
      Y0 := 3;
      dx := 0.05;
      dy := 0.05;
      P := CalculatePointView(mysin, HistoBackround, X0, Y0, dx, dy);          // berechnet Funktion aus Messdaten
   end;
   Canvas.Brush.Color := cllime;
   Canvas.Pen.Color  := cllime;
   DrawPointView(Canvas, HistoBackround, P);
   end;
end;

procedure THixHistoGraph.Resize;                                               // überschreibt die gesetzten Werte aus SubKomponenten, um die Skalen positionieren zu können
begin
  inherited;

   //FXScale.BkColor     := clyellow;                                           // zum Testen
   FXScale.Left        := 1;
   FXScale.Width       := Width - 2;
   FXScale.XGapLeft    := FGapLeft;
   FXScale.XGapRight   := FGapRight;
   FXScale.Top         := Height - FGapBottom + 2;


   //FYScale.BkColor     := clSkyBlue;                                          // zum Testen
   FYScale.Top         := 1;
   FYScale.YGapTop     := GapTop;
   FYScale.YGapBottom  := FXScale.GridHeight;
   FYScale.Left        := 1;
   FYScale.Height      := Height - FGapBottom + FXScale.GridHeight;
   FYScale.Width       := FGapLeft - 1;
end;

procedure THixHistoGraph.DrawGrid;                                             // zeichnet Hintergrundraster

var
   Value : Real;

begin
inherited;
   Canvas.Pen.Color     := FBKGridColor;
   Canvas.Brush.Color   := FBKGridColor;
   Canvas.Pen.Style     := FGridLineStyle;

  begin
   if FGridVisible = grdVer then                                               // Hintergrundraster in Y-Richtung
   begin
   inherited;
      Value := (FXScale.ValMin);
                  while (Value <= FXScale.ValMax) do
                  begin
                  inherited;
                  Canvas.MoveTo((FGapLeft + 1) +
                  round((Width - 2 - (FGapLeft + FGapRight))
                  * ((Value - FXScale.ValMin) / (FXScale.ValMax - FXScale.ValMin))),
                  (Height - FGapBottom));

                  Canvas.LineTo((FGapLeft + 1) +
                  round((ClientWidth - 2 - (FGapRight + FGapLeft))
                  * ((Value - FXScale.ValMin) / (FXScale.ValMax - FXScale.ValMin))),
                   FGapTop);
                  Value := (Value + FXScale.ValGap);
                  end;
   end;

   if FGridVisible = grdHor then                                               // Hintergrundraster in X-Richtung
   begin
   inherited;
     Value := (FYScale.ValMin);
                  while (Value <= FYScale.ValMax) do
                  begin
                  inherited;
                  Canvas.MoveTo(FGapLeft,
                  FGapTop + 1 +
                  round((ClientHeight - (FGapBottom + FGapTop))
                  * ((Value - FYScale.ValMin) / (FYScale.ValMax - FYScale.ValMin))));


                  Canvas.LineTo(Width - FGapRight,
                  FGapTop + 1 +
                  round((ClientHeight - (FGapBottom + FGapTop))
                  * ((Value - FYScale.ValMin) / (FYScale.ValMax - FYScale.ValMin))));

                  Value := (Value + abs(FYScale.ValGap)) ;
                  end;
   end;

   if FGridVisible = grdBoth then                                              // Hintergrundraster in X und Y-Richtung
   begin
   inherited;
      Value := (FXScale.ValMin);
                  while (Value <= FXScale.ValMax) do
                  begin
                  inherited;
                  Canvas.MoveTo((FGapLeft + 1) +
                  round((Width - 2 - (FGapLeft + FGapRight))
                  * ((Value - FXScale.ValMin) / (FXScale.ValMax - FXScale.ValMin))),
                  (Height - FGapBottom));

                  Canvas.LineTo((FGapLeft + 1) +
                  round((ClientWidth - 2 - (FGapRight + FGapLeft))
                  * ((Value - FXScale.ValMin) / (FXScale.ValMax - FXScale.ValMin))),
                   FGapTop);
                  Value := (Value + FXScale.ValGap);
                  end;

       Value := (FYScale.ValMin);
                  while (Value <= FYScale.ValMax) do
                  begin
                  inherited;
                  Canvas.MoveTo(FGapLeft,
                  FGapTop + 1 +
                  round((ClientHeight - (FGapBottom + FGapTop))
                  * ((Value - FYScale.ValMin) / (FYScale.ValMax - FYScale.ValMin))));


                  Canvas.LineTo(Width - FGapRight,
                  FGapTop + 1 +
                  round((ClientHeight - (FGapBottom + FGapTop))
                  * ((Value - FYScale.ValMin) / (FYScale.ValMax - FYScale.ValMin))));

                  Value := (Value + abs(FYScale.ValGap)) ;
                  end;

      end;
  end;
end;

procedure THixHistoGraph.DrawPointView
(ACanvas: TCanvas; const ARect: TRect; const APoints : TPointDynArray);
var
   h : Thandle;
   begin
   h:= SaveDC(ACanvas.Handle);
   try
   IntersectClipRect(ACanvas.Handle, ARect.Left, ARect.Top, ARect.Right, ARect.Bottom); // Zeichenfläche einschränken
   Polyline(ACanvas.Handle, APoints[0], Length(APoints));
   finally
      RestoreDC(ACanvas.Handle, h);
   end;
end;

procedure THixHistoGraph.Paint;
begin
  inherited;
  DrawComponent;
  DrawGrid;
end;

Caps 19. Mär 2015 13:29

AW: Hilfe, bei Parametrisieren
 
Hi,

ich sehe gar kein Hauptprogramm, nur Ereignisbehandlungsroutinen.
Im Hauptprogramm müsstest Du, soweit ich das sehe, irgendwann Deine "externen" Werte einlesen und danach die Funktion zeichnen.

Was für Werte kommen denn eigentlich von extern? Das Argument x der Funktion, oder?

lg Caps

Chris211183 20. Mär 2015 08:17

AW: Hilfe, bei Parametrisieren
 
Hi, ja das sind nur die Berechnungsgrundlagen !
Von extern soll mal ein Ultraschallsignal kommen, welches angezeigt werden soll...

Das ist halt die Frage, wie man das realisiert, als Programmcode

Chris211183 20. Mär 2015 11:42

AW: Hilfe, bei Parametrisieren
 
Das ist mein Ansatz....


Delphi-Quellcode:
procedure THixHistoGraph.DrawMeasureValue;
var
   HistoBackround             : TRect;
   x0, y0, dx, dy             : Real;
   i                          : Integer;
   P                          : TPointDynArray;

begin
      // Hintergrund der Darstellungsfläche
      HistoBackround := Rect(FGapLeft,                                        
                              FGapTop,
                              Width - FGapRight,
                              Height - FGapBottom + 2);

      x0 := 0;
      y0 := 0;
      dx := 0.05;
      dy := 0.05;

      for i:= 0 to (Width - 1) do
      begin
      x0 := i;
      y0 := Height;
      P := CalculatePointView(mysin, HistoBackround, x0, y0, dx, dy);
      // berechnet Funktion aus Messdaten
      Canvas.Brush.Color := cllime;
      Canvas.Pen.Color  := cllime;
      Canvas.Pen.Style  := psSolid;
      DrawPointView(Canvas, HistoBackround, P);
      end;
end;

Caps 20. Mär 2015 12:48

AW: Hilfe, bei Parametrisieren
 
Aber Dein Programm zeichnet zur Zeit nur eine Sinus-Funktion, gel?
Keine andere Funktion o.ä.

lg Caps

Chris211183 20. Mär 2015 13:02

AW: Hilfe, bei Parametrisieren
 
jap, mir gehts halt darum, wie ich das jetzt am besten anstelle, dass mir die Signale halt angezeigt werden...

er sagt auch, dass die Variable P möglicherweise nicht initialisiert wurde, meiner Meinung nach ist sie das aber...

Caps 20. Mär 2015 13:25

AW: Hilfe, bei Parametrisieren
 
Hi,

ohne es ausprobieren zu können - zeichnet er denn nicht?
P ist dann nicht initialisiert, wenn die Schleife nicht ausgeführt wird. Das ist nicht schlimm, aber nach der Schleife hat P keinen Wert, falls die Schleife nicht durchlaufen wurde, falls width = 0.

lg Caps


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:38 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz