<< Click to Display Table of Contents > 

Client Control Interface Manual > Programming Examples > Optimize Performance > Example 1

Example 1
Previous pageReturn to chapter overviewNext page

To demonstrate how to use the CI calls properly we want to give an example code.

Consider you have 20 barcode entities in SAMLight with the entity names barcode1, barcode2, ..., barcode20. We want to change for each barcode:

1.Enable Hatch1 with style 'wavy line without marking the jumps'

2.Enable Hatch2 with style 'zigzag'

A common way to program this changes in C# would be:

Enable Hatching ("slow" method)
 

for (int i = 1; i <= 20; i++)

{

   //generate the entity name and the entity text for each of the 20 barcodes

   string entity_name = "barcode" + Convert.ToString(i);

   string entity_text = "This is the text of " + entity_name;

  //change the text of each entity

  cci.ScChangeTextByName(entity_name, entity_text);

  //enable Hatching1

  cci.ScSetEntityLongData(entity_name, (int)

  ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdEnableHatching1, 1);

  //enable Hatching2

  cci.ScSetEntityLongData(entity_name, (int)

  ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdEnableHatching2, 6);

}

Table 426: Enable Hatching ("slow" method)

This looks fine and will work properly but after every of the 60 CI calls the corresponding entity will get regenerated and the View2D of SAMLight will be updated. This needs a lot of time.

We will now demonstrate how the same goal can be reached by using 3 CI calls instead of 60. To do so we create two strings: containing all the entity names and the text for each of them. But we separate every entry in the string by semicolon and will use the NamesSeparatedBySemicolon flag to change the properties at once. Furthermore every entity will be regenerated only once and the View2D of SAMLight will only be updated after the last entity change was completed. This is achieved by using DontUpdateView and TopLevelOnly flags.

Enable Hatching (optimized performance)
 

//Generate one string 'all_entity_names' with all entity names separated by ";"

//and generate one string 'all_entity_texts' with all entity textes separated by "\v"

string all_entity_names = "barcode1";

string all_entity_texts = "This is the text of barcode 1";

for (int i = 2; i <= 20; i++)

{

   all_entity_names = all_entity_names + ";" + "barcode" + Convert.ToString(i);

   all_entity_texts = all_entity_texts + "\v" + "This is the text of barcode" +

  Convert.ToString(i);

}

//enable entity name separated by semicolon mode

//disable View2D

//enable top level entities only

cci.ScSetMode((int)

ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlModeFlagEntity_NamesSeparatedBySemicolon |

(int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlModeFlagDontUpdateView |

(int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlModeFlagTopLevelOnly);

//change all texts of all entities

cci.ScChangeTextByName(all_entity_names, all_entity_texts);

//enable Hatching1 and Hatching2 for all entities, suppress entity update after enabling Hatching 1

//so the entities will be updated after the enabling of Hatching 2 (second call)

cci.ScSetEntityLongData(all_entity_names,

(int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdEnableHatching1 |

(int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlDoubleDataIdFlagDontUpdateEntity, 1);

cci.ScSetEntityLongData(all_entity_names,

(int)ScComSAMLightClientCtrlFlags.scComSAMLightClientCtrlLongDataIdEnableHatching2, 6);

//reset ScSetMode

cci.ScSetMode(0);

//manually update View2D

cci.ScExecCommand((int)ScComSAMLightClientCtrlExecCommandConstants.scComSAMLightClientCtrlExecCommandUpdateViewNow);

Table 427: Enable Hatching (optimized performance)