Hallo, ich habe Schwierigkeiten, etwas Ähnliches wie die Drag & Drop-Oberflächen zu erstellen, die in (JMP Pro) SEM und Zuverlässigkeitsblockdiagrammen verwendet werden.
Die Idee ist, eine Palette von „Kästchen“ am linken Bildschirmrand anzuzeigen. Ich möchte eines dieser Kästchen auswählen, es in die Bildschirmmitte ziehen, dort ablegen und dann das nächste Kästchen auswählen, es ebenfalls dorthin ziehen usw.
Ich habe schon verschiedene Methoden ausprobiert, unter anderem Griffe und Mausefallen. Ich komme ein Stück weit, aber nicht ganz.
Mein aktueller Code, der Mousetrap verwendet, ist unten dargestellt. Ich kann das Feld oben links in der GraphBox greifen, es über den Bildschirm ziehen und an der gewünschten Stelle ablegen. (Es wird schwarz, sobald es abgelegt ist.) Anschließend kann ich jedoch kein weiteres Feld greifen. Ich kann nur das gerade abgelegte Feld verschieben. Es ist nicht möglich, ein weiteres Feld hinzuzufügen.
Ich entwickle das momentan als Anwendung, bin aber gerne bereit, das zu ändern, falls es hilfreich ist.
Das unten stehende Skript zeigt meinen Code im Application Builder. Die beigefügte Datei enthält die gesamte Anwendung.
Ich fürchte, es gibt Aspekte von Mousetrap, GraphBoxes und den Add Graphics Scripts, die ich einfach nicht verstehe. Kann mir jemand helfen?
// This script is executed when a new module instance is
// created. The pre-defined object "thisModuleInstance" refers
// to the instance object, but other objects such as boxes and
// scripts have not yet been created. Variables declared here are
// scoped to the ModuleInstance namespace.
// This special function will receive parameters passed to CreateInstance()
OnModuleLoad({},
);
thisModuleInstance << Create Objects;
// After this point your module instance objects have been created
// and can be referred to by name (for example, "Button1").
x0=5;
y0=95;
winref = (this module instance << Get Box);
// set graph box scales
winref[framebox(1)] << xaxis(0,100);
winref[framebox(1)] << yaxis(0,100);
// draw box in upper left corner.
pen color("Green");
winref[framebox(1)] << add graphics script(
pen color("Green");
Line({0,90}, {10,90},{10,100}, {0,100},{0,90}));
winref[framebox(1)] << Add Graphics Script(
Mousetrap(
// drag script (mouse down)
(
// if mouse location is within box in upper left corner, then OK to drag.
if(
and(
x>=x0-5,
y>=y0-5,
x<=x0+5,
y<=y0+5
),
(
// set x0 and y0 if that were true
x0 = x;
y0 = y;
// redraw the box at current mouse location while mouse button is down
winref[framebox(1)] << add graphics script(
"Front",
pen color("Green");
Line({x0-5, y0-5}, {x0+5, y0-5}, {x0+5, y0+5}, {x0-5, y0+5}, {x0-5, y0-5}));
)
);
),
(
// mouse up script
// draw a polygon centered at the current mouse location
winref[framebox(1)] << add graphics script(
polygon({x0-5,y0-5},{x0+5,y0-5},{x0+5,y0+5},{x0-5,y0+5},{x0-5,y0-5})
);
// at this point I want to manually reposition the mouse over the original box in the
// upper left, and grab another box.
// Instead, all I can do is grab the box I just created and drag it somewhere else.
)
);
);
Wahrscheinlich möchten Sie nicht ständig neue Grafikskripte hinzufügen, da dies Ihre If()-Anweisung überschreiben und den Framebox-Bereich überfluten würde.

Man kann das viel besser bauen, aber unten ist ein Beispiel, wie es möglich wäre.
Names Default To Here(1);
rects = {};
x0 = 5;
y0 = 95;
x = .;
y = .;
nw = New Window("Example",
Graph Box(
Frame Size(200, 200),
Mousetrap(
x0 = x;
y0 = y;
,
p = EvalExpr(Polygon(
{Expr(x0+5), Expr(y0-5)},
{Expr(x0+5), Expr(y0+5)},
{Expr(x0-5), Expr(y0+5)},
{Expr(x0-5), Expr(y0-5)}
));
Insert Into(rects, Name Expr(p));
);
Pen color("Green");
Line({0,90}, {10,90},{10,100}, {0,100},{0,90});
If(x >= x0 - 5 & y >= y0 - 5 & x <= x0 + 5 & y <= y0 + 5,
Pen color("Green");
Line({x0-5, y0-5}, {x0+5, y0-5}, {x0+5, y0+5}, {x0-5, y0+5}, {x0-5, y0-5});
);
For(i = 1, i <= N Items(rects), i++,
Pen Color("Black");
Eval(rects[i]);
);
);
);
</CODE></P>
<P><SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1766523967638.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_1-1766523967638.png" style="width: 260px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_1-1766523967638.png" style="width: 260px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_1-1766523967638.png" style="width: 260px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_1-1766523967638.png" style="width: 260px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_1-1766523967638.png" style="width: 260px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_1-1766523967638.png" style="width: 260px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_1-1766523967638.png" style="width: 260px;"><span class="lia-inline-image-display-wrapper" image-alt="jthi_1-1766523967638.png" style="width: 260px;"><img src="https://us.v-cdn.net/6038925/uploads/images/89563i0F98FCB07A4441BC/jthi_1-1766523967638.png" role="button" title="jthi_1-1766523967638.png" alt="jthi_1-1766523967638.png" /></span></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></SPAN></P>
<BR />
<P>Bearbeitet: Initialisierung für x und y hinzugefügt</P>
</LINGO-BODY>
<LINGO-SUB id="lingo-sub-921160" slang="en-US" mode="UPDATE" translate="no">Betreff: Erstellung eines Drag-&-Drop-Skripts</LINGO-SUB>
<LINGO-BODY id="lingo-body-921160" slang="en-US" mode="UPDATE">
<P>Ich erhalte:</P>
<P><FONT face="courier new,courier">DisplayBox[EvalContextBox]</FONT><BR /><FONT face="courier new,courier">Name nicht aufgelöst: x beim Zugriff oder der Auswertung von 'x' , x/*###*/</FONT></P>
<P><FONT face="courier new,courier">in Zeile 26</FONT><BR /><BR /></P>
<P>Bleiben x und y auch außerhalb der Mausefalle bestehen?</P>
<P><SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1766525524905.png" style="width: 999px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="hogi_0-1766525524905.png" style="width: 784px;"><span class="lia-inline-image-display-wrapper" image-alt="hogi_0-1766525524905.png" style="width: 784px;"><img src="https://us.v-cdn.net/6038925/uploads/images/89564iE967B41113B5D41E/hogi_0-1766525524905.png" role="button" title="hogi_0-1766525524905.png" alt="hogi_0-1766525524905.png" /></span></SPAN></SPAN></P>
<P><STRONG>bearbeiten</STRONG> :<BR /> Sie "beharren außerhalb der Mausefalle"<BR /> – aber nicht für immer. Anscheinend werden sie zurückgesetzt, sobald die Maustaste losgelassen wird:<BR /> <A href="https://community.jmp.com/t5/Discussions/Can-JMP-graphics-have-this-effect/m-p/921213/highlight/true#M107999" target="_blank">https://community.jmp.com/t5/Discussions/Can-JMP-graphics-have-this-effect/mp/921213/highlight/true#M107999</A></P>
<BR />
<P>Cool, mit dem grünen Rechteck ist die Illusion des „Ziehens“ sehr überzeugend ; )<BR /> Ohne das grüne Rechteck fühlt es sich eher so an, als würde man mit jedem Mausklick ein schwarzes Rechteck hinzufügen.</P>
<P></P>
<iframe src="https://players.brightcove.net/6058004218001/default_default/index.html?videoId=6386912122112" width="280" height="280" allowfullscreen allow="encrypted-media"></iframe>
<P></P>
</LINGO-BODY>
<LINGO-SUB id="lingo-sub-921187" slang="en-US" mode="CREATE" translate="no">Betreff: Erstellung eines Drag-&-Drop-Skripts</LINGO-SUB>
<LINGO-BODY id="lingo-body-921187" slang="en-US" mode="CREATE">
<P>Ich hatte vermutlich x und y im Speicher initialisiert, deshalb funktionierte es nicht. Nachdem ich das Skript mit der Initialisierung von x und y aktualisiert habe, scheint es in einer neuen JMP-Sitzung zu funktionieren.</P>
</LINGO-BODY>
<LINGO-SUB id="lingo-sub-921211" slang="en-US" mode="CREATE" translate="no">Betreff: Erstellung eines Drag-&-Drop-Skripts</LINGO-SUB>
<LINGO-BODY id="lingo-body-921211" slang="en-US" mode="CREATE">
<P>Vielen Dank an <A href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366" target="_blank">@jthi</A> (und an <A href="https://community.jmp.com/t5/user/viewprofilepage/user-id/26800" target="_blank">@hogi</A> für deinen Beitrag)! Ich sollte das für meine Zwecke anpassen können. Und dabei habe ich etwas über Mousetrap, Add Graphics Script und Name Expr gelernt.</P>
<P>Die JMP-Community überrascht mich immer wieder mit ihrer Reaktionsschnelligkeit und ihrem Fachwissen. Vielen Dank dafür!</P>
</LINGO-BODY>
<LINGO-SUB id="lingo-sub-921219" slang="en-US" mode="UPDATE" translate="no">Betreff: Erstellung eines Drag-&-Drop-Skripts</LINGO-SUB>
<LINGO-BODY id="lingo-body-921219" slang="en-US" mode="UPDATE">
<P>Dies ist eine erweiterte Version des Skripts von <A href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366" target="_blank">@jthi</A> :</P>
<P>- Vorhandene Felder können verschoben werden.</P>
<P>- Es wird kein Feld erstellt oder verschoben, wenn der Benutzer auf einen Bereich ohne Feld klickt.</P>
<P>- Die oberste Box dient als unendlicher Speicher für weitere Boxen.</P>
<P></P>
<iframe src="https://players.brightcove.net/6058004218001/default_default/index.html?videoId=6386914707112" width="276" height="280" allowfullscreen allow="encrypted-media"></iframe>
<P></P>
<BR />
<PRE><CODE class=" language-jsl">Names Default To Here( 1 );
squares = {{5, 95}};
x = .;
y = .;
mouseDown = 1;
foundOne = 0;
nw = New Window( "Example",
Graph Box(
Frame Size( 200, 200 ),
Mousetrap(
// find a neighboring square
If( mouseDown,
x0 = x;
y0 = y;
If( N Items( squares ),
kt = KDTable( Matrix( squares ) );
{row, dist} = kt << K nearest rows( {1, 10}, Matrix( {x0, y0} ) );
If( N Items( row ) & dist[1] < 10,
If( row > 1, // keep the one at the top corner
Remove From( squares, row[1] )
);
foundOne = 1;
);
);
);
mouseDown = 0;,
// mouse relesed -> save the square
If( foundOne,
Insert Into( squares, Eval List( {Eval List( {x, y} )} ) )
);
//reset
mouseDown = 1;
foundOne = 0;
);
Pen Color( "Green" );
Line( {0, 90}, {10, 90}, {10, 100}, {0, 100}, {0, 90} ); // 1st square to start with
// dragged square
If( Not( Is Missing( x ) ) & foundOne,
Line( {x - 5, y - 5}, {x + 5, y - 5}, {x + 5, y + 5}, {x - 5, y + 5}, {x - 5, y - 5} )
);
For( i = 1, i <= N Items( squares ), i++,
Pen Color( "Black" );
Eval(
{x0, y0} = squares[i];
Polygon( {x0 + 5, y0 - 5}, {x0 + 5, y0 + 5}, {x0 - 5, y0 + 5}, {x0 - 5, y0 - 5} );
);
);
)
);