Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

ShapeStyle.ToString()

Solved!
Go to solution

Hello,

 

in my application I want to save the settings of an annotation. When I use the annotation.ShapeStyle.ToString() method it only delivers "ShapeStyle". I think

they should give back the name of the actual shape, to use the Shape.Parse() function to get the saved condition.

 

Best regards

 

Gerald

0 Kudos
Message 1 of 9
(5,057 Views)

Hi Gerald,

 

in which relation do you use the annotation? I assume you would like to save the specific comments for the program. Are you using therefore any specific NI libary like NI VISA Class Libary, NI DAQ, or NI Windows?

 

In which libary is the command annotation.ShapeStyle.Tostring() command included?

 

Thanks

 

 

Rupert

0 Kudos
Message 2 of 9
(5,044 Views)

Hi Rupert

 

they are all in the Nationalinstruments.UI.dll.

                   

here is an codesample

 

XYPointAnnotation annotation = new XYPointAnnotation(scatterGraph1.XAxes[0], scatterGraph1.YAxes[0], 1, 1);   
annotation.ShapeStyle = ShapeStyle.Diamond;                                                                   
scatterGraph1.Annotations.Add(annotation);                                                                    

//Save the setting in a String                                     
string saveString = annotation.ShapeStyle.ToString();                                                         

//Load the Settings
annotation.ShapeStyle = (ShapeStyle)ShapeStyle.Parse(typeof(ShapeStyle), saveString);                         

 

 

 

Regards Gerald

 

0 Kudos
Message 3 of 9
(5,041 Views)

Hi Gerald,

 

thanks for the sourcecode - now I am aware what's your aim. I could reproduce the issue about the annotation.ShapeStyle.ToString() -

it doesn't deliver the current shape of the marker.

 

You can use annotation.ShapeStyle.GetType().ToString(), this method allows you to get back the current shape in this order Class+CurrentStyle.

 

Best regards,

 

Rupert

0 Kudos
Message 4 of 9
(5,036 Views)

Ok i tried this and I get the follwoing string:

 

"NationalInstruments.UI.ShapeStyle+DiamondShapeSytleImpl".

 

In which way can I now restaurate this value. My aim is, to save the settings of the annotation in a file. So I save this string. But when I load the file what shall I do whith this string?

 

Regards Gerald

0 Kudos
Message 5 of 9
(5,033 Views)

Hi there,

 

Unfortunately, the ShapeStyle does not provide a way to preserve its properties to a file and load it back when needed. You will have to write your own APIs to do serialize and deserialize them to/from file.

I would suggest preserving properties in XML format is the best way to do it. When parsing the XML, get the values of the properties (that is, converting strings to appropriate types). And, use the ShapeStyle.Create...(..) methods to create a shape style.

 

Regards,

Vijet Patankar

National Instruments

0 Kudos
Message 6 of 9
(5,021 Views)

Hi,

 

thats what I want to do. I want to save the Properties in an XML file. Here a codesample:

 

 

XYPointAnnotation annotation = new XYPointAnnotation(scatterGraph1.XAxes[0], scatterGraph1.YAxes[0], 1, 1);
annotation.ShapeStyle = ShapeStyle.Diamond;
scatterGraph1.Annotations.Add(annotation);

//the Funktion for the save-method ->  don't work
string saveShapeStyleString = annotation.ShapeStyle.ToString();
//the Funktion for the load-method
annotation.ShapeStyle = (ShapeStyle)ShapeStyle.Parse(typeof(ShapeStyle), saveShapeStyleString);

//the Funktion for the save-method -> works
string saveArrowHeadStyleString = annotation.ArrowHeadStyle.ToString();      
//the Funktion for the load-method
annotation.ArrowHeadStyle = (ArrowStyle)ShapeStyle.Parse(typeof(ArrowStyle), saveArrowHeadStyleString);

  

the ShapeStyle .ToString() Method always deliver "ShapeStyle". According to this the ArrowHeadStyle.ToString() delivers the actual value e.g. "EmptySquare". I think it's a Bug in the dll.

 

 

Regards Gerald

0 Kudos
Message 7 of 9
(5,017 Views)
Solution
Accepted by topic author GerryHappy

Hello there,

 

You are quite right for the fact that the ShapeStyle returns the "ShapeStyle" string for different shapes.

 

Note: ShapeStyle and ArrowStyle are not related in the class hiararchy. ArrowStyle is not a sub-class of ShapeStyle (and vice versa).

 

For your use case you could create a method that would check the shape style and return you the correct string.
Something like the following,

public string GetStyleName(Object style)
{
    if(style is ShapeStyle)
    {
        if(style == ShapeStyle.None)
        {
            return "None";
        }
        else if(style == ShapeStyle.Oval)
        {
            return "Oval";
        }
        .
        .
        .
    }
    else if(style is ArrowStyle)
    {
        return style.ToString();
    }
}

 For loading you could create a (factory) method to actually compare the strings and return the a value.

 

public Object GetMyStyleByName(string name, Type type)
{
	if(type == typeof(ShapeStyle))
	{
		if(name == "None")
		{
			return ShapeStyle.None;
		}
		.
		.
		.
	}
 }

 Hope this helps.

 

Regards

Vijet Patankar

National Instruments

0 Kudos
Message 8 of 9
(5,011 Views)

Hello,

 

thank you for your answer. I will take your example as solution for the problem.

 

Best regards

 

Gerald

0 Kudos
Message 9 of 9
(5,006 Views)