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

Refer to Customized Viewer Example.

CustomizedViewerWindow.xaml

<Window x:Class="customizedviewer.CustomizedViewerWindow"
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>

CustomizedViewerWindow.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 baseviewer;
using cadex;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace customizedviewer
{
public partial class CustomizedViewerWindow : Window
{
public CustomizedViewerWindow()
{
InitializeComponent();
myViewer.ViewerApplication = new BaseViewerApplication(myViewer);
myViewer.SizeChanged += ChangeViewCubeGeometry;
myViewer.Viewport.ViewCubeEnabled = true;
myViewer.Viewport.TrihedronEnabled = true;
myViewer.Viewport.GridPlaneEnabled = true;
AddOptionsMenu();
ChangeBackgroundStyle();
ChangeViewCubeStyle();
ChangeMenuStyle();
}
void ChangeBackgroundStyle()
{
myViewer.Viewport.BackgroundStyle = new ModelPrs_BackgroundStyle(new ModelData_Color(0x00303030));
}
void ChangeViewCubeStyle()
{
var aTextColor = new ModelData_Color(Convert.ToInt32(0x00949494));
var aViewCubeStyle = new ModelPrs_ViewCubeStyle();
aViewCubeStyle.SetTextColor(aTextColor);
aViewCubeStyle.SetTrihedronTextColor(aTextColor);
aViewCubeStyle.SetNormalColor(new ModelData_Color(Convert.ToInt32(0x006e6e6e)));
aViewCubeStyle.SetHoveredColor(new ModelData_Color(Convert.ToInt32(0x00545454)));
aViewCubeStyle.SetPressedColor(new ModelData_Color(Convert.ToInt32(0x00474747)));
myViewer.Viewport.ViewCubeStyle = aViewCubeStyle;
}
void ChangeMenuStyle()
{
var aMenuColor = new ModelData_Color(Convert.ToInt32(0x006e6e6e));
myViewer.myMenu.Background = new SolidColorBrush(Color.FromScRgb(1.0f, aMenuColor.R(), aMenuColor.G(), aMenuColor.B()));
myViewer.myFileMenuItem.Background = new SolidColorBrush(Color.FromScRgb(1.0f, aMenuColor.R(), aMenuColor.G(), aMenuColor.B()));
}
void ChangeViewCubeGeometry(object sender, SizeChangedEventArgs e)
{
var aViewCubeMargins = 10;
var aWidth = e.NewSize.Width;
var aHeight = e.NewSize.Height;
var aViewCubeSize = Math.Max(Math.Min(aWidth, aHeight) / 5, 200);
var aMinLeft = new ModelData_Point2dd(aWidth - aViewCubeMargins - aViewCubeSize,
aViewCubeMargins);
var aMaxRight = new ModelData_Point2dd(aMinLeft.X() + aViewCubeSize,
aViewCubeMargins + aViewCubeSize);
myViewer.Viewport.ViewCubeGeometry = new ModelData_Box2d(aMinLeft, aMaxRight);
}
void AddOptionsMenu()
{
MenuItem anOptionsMenu = new MenuItem();
anOptionsMenu.Header = "Options";
MenuItem aGridPlaneItem = new MenuItem();
aGridPlaneItem.Header = "Grid plane";
aGridPlaneItem.IsCheckable = true;
aGridPlaneItem.IsChecked = true;
aGridPlaneItem.Click += onGridPlaneOptionItemClicked;
MenuItem aTrihedronItem = new MenuItem();
aTrihedronItem.Header = "Trihedron";
aTrihedronItem.IsCheckable = true;
aTrihedronItem.IsChecked = true;
aTrihedronItem.Click += onTrihedronOptionItemClicked;
MenuItem aViewCubeItem = new MenuItem();
aViewCubeItem.Header = "View Cube";
aViewCubeItem.IsCheckable = true;
aViewCubeItem.IsChecked = true;
aViewCubeItem.Click += onViewCubeOptionItemClicked;
anOptionsMenu.Items.Add(aGridPlaneItem);
anOptionsMenu.Items.Add(aTrihedronItem);
anOptionsMenu.Items.Add(aViewCubeItem);
myViewer.myMenu.Items.Add(anOptionsMenu);
}
void onGridPlaneOptionItemClicked(object sender, RoutedEventArgs e)
{
var aMenuItem = (MenuItem)sender;
myViewer.Viewport.GridPlaneEnabled = aMenuItem.IsChecked;
}
void onTrihedronOptionItemClicked(object sender, RoutedEventArgs e)
{
var aMenuItem = (MenuItem)sender;
myViewer.Viewport.TrihedronEnabled = aMenuItem.IsChecked;
}
void onViewCubeOptionItemClicked(object sender, RoutedEventArgs e)
{
var aMenuItem = (MenuItem)sender;
myViewer.Viewport.ViewCubeEnabled = aMenuItem.IsChecked;
}
}
}
Defines a 2D bounding box.
Definition: ModelData_Box2d.hxx:30
Defines an RGBA color (with alpha channel).
Definition: ModelData_Color.hxx:34
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22

App.xaml

<Application x:Class="customizedviewer.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="CustomizedViewerWindow.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 customizedviewer
{
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();
}
}
}
}