Hide menu
Loading...
Searching...
No Matches
visualization/qtquick_qml/pmiviewer/main.cxx

Refer to PMI Viewer Example

PMIViewerApplication.hxx

// ****************************************************************************
// $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.
//
// ****************************************************************************
#ifndef __PMIViewerApplication_HeaderFile
#define __PMIViewerApplication_HeaderFile
#include "../baseviewer/BaseViewerApplication.hxx"
class PMIViewerApplication : public BaseViewerApplication
{
Q_OBJECT
public:
PMIViewerApplication();
void CreateSceneNodes() override;
};
#endif // __PMIViewerApplication_HeaderFile

PMIViewerApplication.cxx

// ****************************************************************************
// $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.
//
// ****************************************************************************
#define __CADEX_PREVIEW_PMI 1
#include "PMIViewerApplication.hxx"
#include <cadex/ModelData_Appearance.hxx>
#include <cadex/ModelData_Color.hxx>
#include <cadex/ModelData_Instance.hxx>
#include <cadex/ModelData_PMIData.hxx>
#include <cadex/ModelData_PMIGraphicalElement.hxx>
#include <cadex/ModelData_PMITable.hxx>
#include <cadex/ModelPrs_SceneNodeFactory.hxx>
#include <deque>
#include <iostream>
using namespace cadex;
namespace {
class ModelVisitor : public ModelData_Model::CombinedElementVisitor
{
public:
ModelVisitor (const ModelPrs_SceneNode& theRoot, const ModelPrs_SceneNodeFactory& theFactory) :
myFactory (theFactory)
{
myNodes.push_back (theRoot);
}
void VisitLeave (const ModelData_SceneGraphElement& /*theSGE*/) override
{
myNodes.pop_back();
}
bool VisitEnter (const ModelData_SceneGraphElement& theSGE) override
{
auto anSGENode = myFactory.CreateNode (theSGE);
myNodes.back().AddChildNode (anSGENode);
myNodes.push_back (anSGENode);
AddPMINodes (theSGE);
return true;
}
void operator() (const ModelData_Part& thePart) override
{
auto aPartNode = myFactory.CreateNode (thePart);
myNodes.back().AddChildNode (aPartNode);
AddPMINodes (thePart);
auto aRep = thePart.BRepRepresentation();
auto aRepNode = myFactory.CreateNode (aRep);
aPartNode.AddChildNode (aRepNode);
}
void AddPMINodes (const ModelData_SceneGraphElement& theSGE)
{
ModelData_Appearance anAppearance (ModelData_Color (0.0f, 0.0f, 0.0f, 1.0f));
ModelPrs_SceneNode aPMIRootNode;
aPMIRootNode.SetAppearance (anAppearance);
for (ModelData_PMITable::PMIDataIterator anIt (theSGE.PMI()); anIt.HasNext();) {
auto anElement = anIt.Next();
if (anElement) {
auto aPMINode = myFactory.CreateNode (anElement.GraphicalElement());
aPMIRootNode.AddChildNode (aPMINode);
}
}
myNodes.back().AddChildNode (aPMIRootNode);
}
private:
std::deque<ModelPrs_SceneNode> myNodes;
};
} // end of unnamed namespace
PMIViewerApplication::PMIViewerApplication()
{
myReaderParameters.ReadPMI() = true;
}
void PMIViewerApplication::CreateSceneNodes()
{
ModelVisitor aVisitor (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 combined methods VisitEnter() and VisitLeave() to visit all elements.
Definition: ModelData_Model.hxx:123
Iterator over added PMIData items, which contains graphical and semantical elements.
Definition: ModelData_PMITable.hxx:81
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

main.cxx

// ****************************************************************************
// $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.
//
// ****************************************************************************
#include "PMIViewerApplication.hxx"
#include <cadex/LicenseManager_Activate.h>
#include <QtCore/QUrl>
#include <QtWidgets/QApplication>
#include "../../../cadex_license.cxx"
using namespace cadex;
int main (int argc, char *argv[])
{
auto aKey = LicenseKey::Value();
//activate the license (aKey must be defined in cadex_license.cxx)
if (!CADExLicense_Activate (aKey)) {
qCritical ("Failed to activate CAD Exchanger license.");
return 1;
}
// Must set dpi scaling before creating an application.
QCoreApplication::setAttribute (Qt::AA_EnableHighDpiScaling);
// Create QApplication because Qt.labs.platform module requires Qt Widgets library.
// For more information see https://doc.qt.io/qt-5.10/qml-qt-labs-platform-filedialog.html
QApplication app (argc, argv);
PMIViewerApplication anApp;
if (anApp.Initialize (QUrl ("qrc:/qml/BaseViewerWindow.qml"), "viewPort")) {
return app.exec();
}
return 0;
}