-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
329 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
SPDX-FileCopyrightText: 2024 Ilya Pominov <[email protected]> | ||
SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
#include "interactivetexturedplane.h" | ||
|
||
#include <AIS_DisplayMode.hxx> | ||
#include <Graphic3d_Texture2Dplane.hxx> | ||
#include <Prs3d_ShadingAspect.hxx> | ||
|
||
namespace ExamplesBase { | ||
|
||
class InteractiveTexturedPlanePrivate | ||
{ | ||
friend class InteractiveTexturedPlane; | ||
|
||
TCollection_AsciiString textureFileName; | ||
}; | ||
|
||
IMPLEMENT_STANDARD_RTTIEXT(InteractiveTexturedPlane, InteractiveSurfacePlane) | ||
|
||
InteractiveTexturedPlane::InteractiveTexturedPlane() | ||
: InteractiveSurfacePlane() | ||
, d(new InteractiveTexturedPlanePrivate) | ||
{ | ||
SetDisplayMode(AIS_Shaded); | ||
|
||
Attributes()->SetupOwnShadingAspect(); | ||
auto shadingAspect = Attributes()->ShadingAspect()->Aspect(); | ||
auto material = shadingAspect->FrontMaterial(); | ||
material.SetColor(Quantity_NOC_WHITE); | ||
material.SetTransparency(.001); | ||
shadingAspect->SetFrontMaterial(material); | ||
shadingAspect->SetTextureMapOn(true); | ||
|
||
setTextureFileName("../Textures/barcode2.png"); | ||
} | ||
|
||
InteractiveTexturedPlane::~InteractiveTexturedPlane() | ||
{ | ||
delete d; | ||
} | ||
|
||
TCollection_AsciiString InteractiveTexturedPlane::textureFileName() const | ||
{ | ||
return d->textureFileName; | ||
} | ||
|
||
void InteractiveTexturedPlane::setTextureFileName(const TCollection_AsciiString &fname) | ||
{ | ||
d->textureFileName = fname; | ||
Handle(Graphic3d_Texture2Dplane) texture = new Graphic3d_Texture2Dplane(d->textureFileName); | ||
texture->DisableRepeat(); | ||
texture->DisableModulate(); | ||
|
||
auto shadingAspect = Attributes()->ShadingAspect()->Aspect(); | ||
shadingAspect->SetTextureMap(texture); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
SPDX-FileCopyrightText: 2024 Ilya Pominov <[email protected]> | ||
SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
#ifndef INTERACTIVETEXTUREDPLANE_H | ||
#define INTERACTIVETEXTUREDPLANE_H | ||
|
||
#include "interactivesurfaceplane.h" | ||
|
||
namespace ExamplesBase { | ||
|
||
class InteractiveTexturedPlanePrivate; | ||
|
||
class InteractiveTexturedPlane : public InteractiveSurfacePlane | ||
{ | ||
DEFINE_STANDARD_RTTIEXT(InteractiveTexturedPlane, InteractiveSurfacePlane) | ||
public: | ||
InteractiveTexturedPlane(); | ||
~InteractiveTexturedPlane(); | ||
|
||
TCollection_AsciiString textureFileName() const; | ||
void setTextureFileName(const TCollection_AsciiString &fname); | ||
|
||
private: | ||
InteractiveTexturedPlanePrivate *d; | ||
}; | ||
|
||
DEFINE_STANDARD_HANDLE(InteractiveTexturedPlane, InteractiveSurfacePlane) | ||
|
||
} | ||
|
||
#endif // INTERACTIVETEXTUREDPLANE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
project(TexturedPlain VERSION 0.1 LANGUAGES CXX) | ||
|
||
set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
|
||
set(PROJECT_H | ||
|
||
) | ||
|
||
set(PROJECT_SOURCES | ||
main.cpp | ||
viewport.h | ||
viewport.cpp | ||
) | ||
|
||
add_executable(TexturedPlain | ||
${PROJECT_SOURCES} | ||
) | ||
|
||
target_include_directories( | ||
TexturedPlain | ||
PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/../ | ||
) | ||
|
||
target_link_libraries(TexturedPlain PUBLIC ExamplesBase PRIVATE Qt5::Widgets) | ||
|
||
target_link_libraries(TexturedPlain PRIVATE | ||
TKernel TKMath TKService TKV3d TKOpenGl | ||
TKBRep TKIGES TKSTL TKVRML TKSTEP TKSTEPAttr TKSTEP209 | ||
TKSTEPBase TKGeomBase TKGeomAlgo TKG3d TKG2d | ||
TKXSBase TKShHealing TKHLR TKTopAlgo TKMesh TKPrim | ||
TKCDF TKBool TKBO TKFillet TKOffset TKLCAF TKCAF TKVCAF | ||
TKBin TKXml TKRWMesh | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
SPDX-FileCopyrightText: 2024 Ilya Pominov <[email protected]> | ||
SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
#include <QApplication> | ||
|
||
#include <ExamplesBase/interactiveobjectsmainwindow.h> | ||
|
||
#include "viewport.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
|
||
ExamplesBase::InteractiveObjectsMainWindow w; | ||
w.setViewport(new Viewport); | ||
w.setGeometry(600, 360, 1200, 720); | ||
w.show(); | ||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
SPDX-FileCopyrightText: 2024 Ilya Pominov <[email protected]> | ||
SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
#include "viewport.h" | ||
|
||
#include <QDebug> | ||
#include <QMenu> | ||
|
||
#include <AIS_InteractiveContext.hxx> | ||
|
||
#include <ExamplesBase/ModelLoader/steploader.h> | ||
#include <ExamplesBase/Objects/interactivetexturedplane.h> | ||
#include <ExamplesBase/utility.h> | ||
#include <gp_QuaternionSLerp.hxx> | ||
#include <TopoDS_Face.hxx> | ||
|
||
class ViewportPrivate | ||
{ | ||
friend class Viewport; | ||
|
||
Handle(AIS_Shape) model; | ||
}; | ||
|
||
Viewport::Viewport() | ||
: ExamplesBase::InteractiveObjectsViewport() | ||
, d_ptr(new ViewportPrivate) | ||
{ | ||
context()->IsoOnPlane(Standard_False); | ||
context()->SetIsoNumber(1); | ||
|
||
QMetaObject::invokeMethod(this, [this]() { | ||
const char *path = "../Models/45deg AdjMirr Adapter Left Rev1.STEP"; | ||
ExamplesBase::StepLoader loader; | ||
d_ptr->model = new AIS_Shape(loader.load(path)); | ||
d_ptr->model->SetDisplayMode(AIS_Shaded); | ||
context()->Display(d_ptr->model, Standard_True); | ||
fitInView(); | ||
}, Qt::QueuedConnection); | ||
} | ||
|
||
Viewport::~Viewport() | ||
{ | ||
delete d_ptr; | ||
} | ||
|
||
void Viewport::objectsViewMenuRequest(const Handle(AIS_InteractiveObject) &obj, QMenu &menu) | ||
{ | ||
createContextMenu(obj, gp_XYZ(), menu); | ||
} | ||
|
||
void Viewport::contextMenuRequest(const Handle(AIS_InteractiveObject) &object, | ||
const gp_XYZ &pickedPoint, | ||
QMenu &menu) | ||
{ | ||
createContextMenu(object, pickedPoint, menu); | ||
} | ||
|
||
void Viewport::createContextMenu(const Handle(AIS_InteractiveObject) &object, | ||
const gp_XYZ &pickedPoint, | ||
QMenu &menu) | ||
{ | ||
if (object && object == d_ptr->model) { | ||
menu.addAction(tr("Plane"), this, [this, object, pickedPoint]() { | ||
const auto shape = d_ptr->model->Shape(); | ||
const auto face = ExamplesBase::findFaceByPoint(shape, pickedPoint); | ||
if (face.IsNull()) { | ||
return; | ||
} | ||
|
||
Handle(ExamplesBase::InteractiveTexturedPlane) plane = new ExamplesBase::InteractiveTexturedPlane; | ||
plane->setUmax(20.); | ||
plane->setVmax(10.); | ||
plane->setTextureFileName("../Textures/barcode.png"); | ||
addToContext(plane, pickedPoint, tr("Texture"), object); | ||
|
||
gp_Dir D1U; | ||
const auto normal = ExamplesBase::getNormal(face, pickedPoint, &D1U); | ||
gp_Trsf trsf; | ||
auto xAxis = D1U.Crossed(normal); | ||
auto yAxis = normal.Crossed(xAxis); | ||
gp_Mat mat(xAxis.XYZ(), yAxis.XYZ(), normal.XYZ()); | ||
trsf.SetRotationPart(gp_Quaternion(mat)); | ||
gp_Pnt pos(pickedPoint); | ||
pos.Translate(gp_Vec(normal) * .1); | ||
pos.Translate(gp_Vec(yAxis) * plane->getVmax() * -1.); | ||
trsf.SetTranslationPart(pos.XYZ()); | ||
context()->SetLocation(plane, trsf); | ||
}); | ||
return; | ||
} | ||
|
||
auto interactive = Handle(ExamplesBase::InteractiveObject)::DownCast(object); | ||
if (interactive) { | ||
menu.addAction(tr("Remove"), this, [this, interactive]() { | ||
removeFromContext(interactive); | ||
}); | ||
menu.addSeparator(); | ||
if (manipulatorAttachedObject() != interactive) { | ||
menu.addAction(tr("Transform"), this, [this, interactive]() { | ||
showManipulator(interactive); | ||
}); | ||
} | ||
if (editorAttachedObject() != interactive) { | ||
menu.addAction(tr("Edit"), this, [this, interactive]() { | ||
showEditor(interactive); | ||
}); | ||
} | ||
} | ||
|
||
if (manipulatorAttachedObject()) { | ||
menu.addAction(tr("End transform"), this, [this]() { | ||
removeManipulator(); | ||
}); | ||
} | ||
if (editorAttachedObject()) { | ||
menu.addAction(tr("End edit"), this, [this]() { | ||
removeEditor(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
SPDX-FileCopyrightText: 2024 Ilya Pominov <[email protected]> | ||
SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
#ifndef VIEWPORT_H | ||
#define VIEWPORT_H | ||
|
||
#include <ExamplesBase/Viewport/interactiveobjectsviewport.h> | ||
|
||
class ViewportPrivate; | ||
|
||
class Viewport : public ExamplesBase::InteractiveObjectsViewport | ||
{ | ||
public: | ||
Viewport(); | ||
~Viewport(); | ||
|
||
protected: | ||
void objectsViewMenuRequest(const Handle(AIS_InteractiveObject) &obj, QMenu &menu) final; | ||
|
||
void contextMenuRequest(const Handle(AIS_InteractiveObject) &object, | ||
const gp_XYZ &pickedPoint, | ||
QMenu &menu) final; | ||
|
||
private: | ||
void createContextMenu(const Handle(AIS_InteractiveObject) &object, | ||
const gp_XYZ &pickedPoint, | ||
QMenu &menu); | ||
|
||
private: | ||
ViewportPrivate *const d_ptr; | ||
}; | ||
|
||
#endif // VIEWPORT_H |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.