More scripts: Dialog
Syntax Highlighing:
comments, key words, predefined symbols, class members & methods, functions & classes
# Vector Combinations Example with Dialog
# also written for autotesting at MicroImages
#
# Developed by: David Breitwisch
# Started: 11 October 2006
# Global variables
class VECTOR Vsource, Voperator, Vdest;
string operation;
class XMLDOC docmain;
class XMLNODE nodemain;
class GUI_DLG dlgmain;
# Callback functions
proc OnSourcePressed ( ) {
dlgmain.GetCtrlByID("op").SetEnabled(true);
GetInputVector(Vsource);
}
proc OnOperatorPressed ( ) {
dlgmain.GetCtrlByID("run").SetEnabled(true);
GetInputVector(Voperator);
}
proc OnOpSelection ( ) {
operation = dlgmain.GetCtrlByID("operation").GetValueStr();
}
proc OnRunPressed ( ) {
clear();
GetOutputVector(Vdest);
class STATUSDIALOG sd;
sd.Create();
class STATUSCONTEXT sc = sd.CreateContext();
sc.Message = "Processing Vectors...";
switch (operation) {
case "AND" :
Vdest = VectorAND(Voperator, Vsource);
break;
case "OR" :
Vdest = VectorOR(Voperator, Vsource);
break;
case "XOR" :
Vdest = VectorXOR(Voperator, Vsource);
break;
case "MERGE" :
Vdest = VectMerge(Voperator, Vsource);
break;
case "SUBTRACT" :
Vdest = VectorSubtract(Voperator, Vsource);
break;
case "REPLACE" :
Vdest = VectorReplace(Voperator, Vsource);
break;
case "EXT_IC" :
Vdest = VectorExtract(Voperator, Vsource, "InsideClip");
break;
case "EXT_PI" :
Vdest = VectorExtract(Voperator, Vsource, "PartInside");
break;
case "EXT_PO" :
Vdest = VectorExtract(Voperator, Vsource, "PartOutside");
break;
case "EXT_IB" :
Vdest = VectorExtract(Voperator, Vsource, "InsideBorder");
break;
case "EXT_OB" :
Vdest = VectorExtract(Voperator, Vsource, "OutsideBorder");
break;
case "EXT_CI" :
Vdest = VectorExtract(Voperator, Vsource, "CompInside");
break;
case "EXT_CO" :
Vdest = VectorExtract(Voperator, Vsource, "CompOutside");
break;
default :
PopupMessage("Invalid selection!"); # Shouldn't happen
}
sd.Destroy();
print("Process Completed");
}
proc OnDlgOpen( ) {
dlgmain.GetCtrlByID("op").SetEnabled(false);
dlgmain.GetCtrlByID("run").SetEnabled(false);
OnOpSelection();
}
# Starting main portion of the script here
clear();
# If this script is not being run internally at MI for testing purposes, create the dialog for user interaction
$ifndef _MI_INTERNAL_AUTOTEST_MODE
string xml$ = '<?xml version="1.0"?>
<root>
<dialog id = "main" title = "Vector Combinations" OnOpen="OnDlgOpen();" buttons="">
<pushbutton id = "src" name = "Input Source Vector..." OnPressed = "OnSourcePressed();" />
<pushbutton id = "op" name = "Intput Operator Vector..." OnPressed = "OnOperatorPressed();" />
<combobox id = "operation" default = "AND" OnSelection = "OnOpSelection();">
<item Value="AND">VectorAND</item>
<item Value="OR">VectorOR</item>
<item Value="XOR">VectorXOR</item>
<item Value="MERGE">VectorMerge</item>
<item Value="SUBTRACT">VectorSubtract</item>
<item Value="REPLACE">VectorReplace</item>
<item Value="EXT_IC">VectorExtract - Inside Clip</item>
<item Value="EXT_PI">VectorExtract - Part Inside</item>
<item Value="EXT_PO">VectorExtract - Part Outside</item>
<item Value="EXT_IB">VectorExtract - Inside Border</item>
<item Value="EXT_OB">VectorExtract - Outside Border</item>
<item Value="EXT_CI">VectorExtract - Completely Inside</item>
<item Value="EXT_CO">VectorExtract - Completely Outside</item>
</combobox>
<pushbutton id = "run" name = "Run" OnPressed = "OnRunPressed();" />
</dialog>
</root>' ;
numeric err = docmain.Parse(xml$);
if ( err < 0 ) {
PopupError( err );
Exit( );
}
nodemain = docmain.GetElementByID( "main" );
if ( nodemain == 0 ) {
PopupMessage( "Could not find main dialog node in XML document" );
Exit();
}
dlgmain.SetXMLNode(nodemain);
numeric ret = dlgmain.DoModal();
if (ret == -1) {
Exit();
}
# Otherwise, just start processing as the symbols will have been preloaded by the autotesting program
$else
OnRunPressed();
$endif