Hide menu
Loading...
Searching...
No Matches
visualization/wpf/pmiviewer/App.xaml.cs

Refer to PMI Viewer Example.

PMIViewerApplication.cs

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
using baseviewer;
using cadex;
using System.Collections.Generic;
namespace pmiviewer
{
class ModelVisitor : ModelData_Model.CombinedElementVisitor
{
public ModelVisitor(ModelPrs_SceneNode theRoot, ModelPrs_SceneNodeFactory theFactory)
{
myFactory = theFactory;
myNodes.Push(theRoot);
}
public override void VisitLeave(ModelData_SceneGraphElement theSGE)
{
myNodes.Pop();
}
public override bool VisitEnter(ModelData_SceneGraphElement theSGE)
{
var anSGENode = myFactory.CreateNode (theSGE);
myNodes.Peek().AddChildNode(anSGENode);
myNodes.Push(anSGENode);
AddPMINodes(theSGE);
return true;
}
public override void Apply(ModelData_Part thePart)
{
var aPartNode = myFactory.CreateNode(thePart);
myNodes.Peek().AddChildNode(aPartNode);
AddPMINodes(thePart);
var aRep = thePart.BRepRepresentation();
var aRepNode = myFactory.CreateNode(aRep);
aPartNode.AddChildNode (aRepNode);
}
private void AddPMINodes(ModelData_SceneGraphElement theSGE)
{
ModelData_Appearance anAppearance = new ModelData_Appearance(new ModelData_Color(0.0f, 0.0f, 0.0f, 1.0f));
aRootNode.SetAppearance(anAppearance);
while (anIt.HasNext())
{
var anElement = anIt.Next();
if (anElement != null)
{
var aPMINode = myFactory.CreateNode(anElement.GraphicalElement());
aRootNode.AddChildNode(aPMINode);
}
}
myNodes.Peek().AddChildNode(aRootNode);
}
private Stack<ModelPrs_SceneNode> myNodes = new Stack<ModelPrs_SceneNode>();
};
class PMIViewerApplication : BaseViewerApplication
{
public PMIViewerApplication(BaseViewer theViewer) : base(theViewer)
{
myReaderParameters.SetReadPMI(true);
}
protected override void CreateSceneNodes()
{
ModelVisitor aVisitor = new ModelVisitor(myRoot, aFactory);
myModel.Accept(aVisitor);
}
}
}
Provides an interface to appearance which is a collection of visual styles.
Definition: ModelData_Appearance.hxx:39
Defines an RGBA color (with alpha channel).
Definition: ModelData_Color.hxx:34
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
Iterator over added PMIData items, which contains graphical and semantical elements.
Definition: ModelData_PMITable.hxx:81
Defines a container storing PMI data.
Definition: ModelData_PMITable.hxx:40
Defines a leaf node in the scene graph hiearchy.
Definition: ModelData_Part.hxx:35
ModelData_BRepRepresentation BRepRepresentation() const
Definition: ModelData_Part.cxx:360
Base class for part, instance and assembly.
Definition: ModelData_SceneGraphElement.hxx:39
ModelData_PMITable PMI() const
Returns a PMI table.
Definition: ModelData_SceneGraphElement.cxx:255
Creates a scene nodes and its children from input data model objects.
Definition: ModelPrs_SceneNodeFactory.hxx:53
Represents a node in the visual scene graph.
Definition: ModelPrs_SceneNode.hxx:44
bool AddChildNode(ModelPrs_SceneNode &theNode)
Adds theNode to children. Returns false if the node already has a parent, otherwise returns true.
Definition: ModelPrs_SceneNode.cxx:787
void SetAppearance(const ModelData_Appearance &theAppearance)
Definition: ModelPrs_SceneNode.cxx:894
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22

PMIViewerWindow.xaml

<Window x:Class="pmiviewer.PMIViewerWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:baseviewer="clr-namespace:baseviewer"
mc:Ignorable="d"
Title="CAD Exchanger" Height="600" Width="1000">
<baseviewer:BaseViewer x:Name="myViewer"></baseviewer:BaseViewer>
</Window>

PMIViewerWindow.xaml.cs

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
using System.Windows;
namespace pmiviewer
{
public partial class PMIViewerWindow : Window
{
public PMIViewerWindow()
{
InitializeComponent();
myViewer.ViewerApplication = new PMIViewerApplication(myViewer);
}
}
}

App.xaml

<Application x:Class="pmiviewer.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="PMIViewerWindow.xaml">
</Application>

App.xaml.cs

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
using cadex;
using System.Runtime.InteropServices;
using System.Windows;
namespace pmiviewer
{
public partial class App : Application
{
// For more information see https://stackoverflow.com/questions/8836093/how-can-i-specify-a-dllimport-path-at-runtime
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool SetDllDirectory(string lpPathName);
public App()
{
// Add runtime path to CAD Exchanger libraries (e.g. use libraries compiled with Visual Studio 2015)
SetDllDirectory("../../../../../../../win64/vc14.1/bin");
string aKey = LicenseKey.Value();
// Activate the license(aKey must be defined in cadex_license.cs)
if (!LicenseManager.Activate(aKey))
{
MessageBox.Show("Failed to activate CAD Exchanger license.");
Shutdown();
}
}
}
}