Author Topic: Hugin Example 4(C#): Load and inspect a network in a Windows.Form applicat  (Read 15641 times)

Offline mortenaagaard

  • Newbie
  • *
  • Posts: 6
    • View Profile
Hi Hugin-team!
I have carefully followed the instructions in the manual "" how to construct the example "". The instructions works perfect, but the application fails with a general errormessage "Parse: An error occurred during parsing. If a parse error handling function was specified, it will have been called a description of the error and its location in the source."

The examples I run works perfectly within Hugin environment and I have tried obbn, net and hkb.

Thanks in advance.

I use Hugin 6.9 and Visual Studio 2005 and C# with SP2(I believe)

Offline Martin

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 613
    • View Profile
Hello.

The problem is most likely because you are trying to load a Hugin class description or hkb-file as a flat network file.

The code in example 4 'Load and inspect a network in a Windows.Form application' expects a flat network file.
This can be seen by looking at which of the overloaded constructors that is used for creating the runtime domain:
Domain(String, ParseListener)   Constructs a domain from a NET file. 

You could take the Easy solution:
The default behavior from the Hugin GUI is to save a network as a class-description. You should save the network as a flat net-file from the Hugin GUI application. (Save As.., then select *.net in the 'files of type' dropdown). The example code should be able to load the file.


...Or you could Implement a custom ParseListener:
Unfortunately the example doesn't implement a parseError-function. You could implement your own ParseListener and have the error description displayed in a MessageBox.

1) Add a subclass to the HuginControl-class:
Code: [Select]
    public class HuginControl : System.Windows.Forms.Panel
    {
    [...]
        public class MyParseListener : ParseListener {
            public void ParseError(size_t position, String msg) {
                MessageBox.Show("Parse error:\n" +msg + "\nAt line: " + position);
            }
        }
    [...]
    }


2) Use the custom ParseListener when loading the network. Replace the line:
Code: [Select]
                Domain dom = new Domain(path, new DefaultClassParseListener());
with
Code: [Select]
                Domain dom = new Domain(path, new MyParseListener());


I hope this helps.

(PS: Loading networks from hkb or class-descriptions: A class description should be loaded using a ClassCollection and then passing the corresponding class to the Domain constructor. A hkb-file is loaded using the Domain(String) constructor.)
Hugin Expert A/S

Offline mortenaagaard

  • Newbie
  • *
  • Posts: 6
    • View Profile
Thank you. I apologize for your inconvinience.
It was a good answer.

Morten Aagaard