0
Under review

How do I display pipe properties?

Mark4965 9 years ago updated by anonymous 5 years ago 3

Good Afternoon,


First off, I've really enjoyed using Helix and as a new user of WPF and graphical programming, I have found Helix very easy to use as well a aid during my learning process. The work put into this project is much appreciated!


I am currently working on a program where the user can create various elements (pipes, spheres, etc.) by inputting the appropriate inputs and graphically display them in the viewport.


Up to now everything has been pretty straight forward. Where I've been hung up the last several days is how to display the properties of the elements once selected with the mouse. For example, if user creates a pipe and then selects it a window would display the diameter, inner diameter, and Point1/2 coordinates. From what I can tell the BuildingDemo might provide a good example as to how this is accomplished however the PropertyGrid remains blank when I select something.


If anyone could provide some insight or some example code I would be extremely grateful. If you need more information please let me know.

Under review

Hi Mark, there was an issue with the wrong BrowsableAttribute being used in the models. The PropertyGrid is set to require [System.ComponentModel.Browsable]. See the updated example source code on github.

Thanks for looking at this and for the reply. I will take a look once I get home.


I was able to come up with a work around which ended up being a better fit for what I ultimately needed. Once i figured this out i felt a bit silly as it seemed so obvious. I'll post a source code example as well once I get home.

Øystein,


The property window is now being populated. Thanks again for looking into the issue!


As for the work around I eventually stumbled into see the example code below. For example purposes I'm manually adding the pipe properties. In my actual program the user inputs the desired values in a textbox and clicks the "AddElement_Click" button to incorporate the element.

public void AddElement_Click(object sender, RoutedEventArgs e)
{
    PipeVisual3D tubenew = new PipeVisual3D();
 
    tubenew.Material = Materials.Green;
    tubenew.Point1 = new Point3D(0, 0, 0);
    tubenew.Point2 = new Point3D(0, 5, 0);
    tubenew.Diameter = 0.5;
    tubenew.InnerDiameter = 0.4;

    View1.Children.Add(tubenew);
}

Using the ViewModel.cs file from BuildingDemo and the code below, I am able to obtain the pipe properties to display in a format of my choosing.


private void CheckElement_OnMouseDown(object sender, MouseButtonEventArgs e)
{
    var viewport = (HelixViewport3D)sender;
    var firstHit = viewport.Viewport.FindHits(e.GetPosition(viewport)).FirstOrDefault();
    if (firstHit != null)
    {
        GetDiameter = HelixToolkit.Wpf.PipeVisual3D.DiameterProperty;
        GetInnerDiameter = HelixToolkit.Wpf.PipeVisual3D.InnerDiameterProperty;

        var a = firstHit.Visual.GetValue(GetDiameter);
        var b = firstHit.Visual.GetValue(GetInnerDiameter);
    }
}

If anyone sees a better or more elegant way of pulling the properties without using the PropertyGrid I'd be happy to see/hear it. I'm still learning and trying to make my code more efficient so any constructive comments or suggestions are more than welcome!


Mark