# AMCAX-Daemon Introduction
[![en-us](https://img.shields.io/badge/en-us-yellow.svg)](./README.md)
[![中文-简体](https://img.shields.io/badge/%E4%B8%AD%E6%96%87-%E7%AE%80%E4%BD%93-red.svg)](./README.zh_cn.md)
**Version 1.0.3**
AMCAX-Daemon showcases some basic functions that AMCAX geometry kernel supports. There are more functions that can be supported by the kernel but currently not used by Daemon.
Please be informed that this project **does not** come with an AMCAX geometry kernel license, you will need to apply the license on your own.
## Contents
- [How to Use](#how-to-use)
- [User Interfaces](#user-interfaces)
- [Create / Delete / Move Geometry Objects](#create--delete--move-geometry-objects)
- [Modify Geometry Objects](#modify-geometry-objects)
- [Persistent Geometry Objects](#persistent-geomeetry-objects)
- [Auxillary Functions](#auxillary-functions)
- [How to Build](#how-to-build)
- [Prerequisite](#prerequisite)
- [Steps](#steps)
- [Tutorial](#tutorial)
- [Code Structure Overview](#code-structure-overview)
- [Create Geometry Objects](#create-geometry-objects)
- [Modify Geometry Objects](#modify-geometry-objects-1)
- [Persistent Geometry Objects](#persistent-geomeetry-objects-1)
- [Known Issues](#known-issues)
- [License](#license)
- [Contact Us](#contact-us)
## How to Use
### User Interfaces
Refer to figures below to locate the operation areas of AMCAX-Daemon
![Refer to figures below to locate the operation areas of AMCAX-Daemon](./doc/pic/screenshot/screenshot.png)
### Create / Delete / Move Geometry Objects
- To create a new geometry object
Activate **BRep** tab and choose the type of object, and then:
- For face type: Click on the render area to specify multiple points in sequence, once you are done, press `Enter`.
- For other types: A dialog will pop up, specify the geometry object's parameters in the dialog and click `OK`
- To delete objects, select the objects and press `Delete` key.
- To move objects, select the objects, hold the left mouse button, move to the target point, then release the button
### Modify Geometry Objects
- To edit objects, on the leftside, there's an edit toolbar, choose the kind of operation from the toolbar, pick up objects in sequence to operate on, and then press `Enter` key to apply the operation on selected objects.
### Persistent Geometry Objects
![File Menu](./doc/pic/screenshot/screenshot-file.png)
- **Save**: Save the object in `*.amcax` format, which is AMCAX's proprietary format and supports TMSpline, SubD, BRep.
- **Save As**: Save the object in the format`*.amcax`, `*.stp` `*step`.
- **Save Selected**: You can choose to save the object in the format `*.amcax`, `*.stp` `*step`.
- All of the above related features are located under the `File` menu.
### Auxillary Functions
- Change viewpoint
- Rotate: Hold the right mouse button and move to adjust
- Pan: Press left/right/up/down key
- Undo/Redo
## How to Build
### Prerequisite
- CMake 3.27 +
- Visual Studio 2019
- Extension: Qt VS Tool (Qt Versions Configured)
- QT 5.15.2
- Add qmake path (eg. D:\Qt\5.15.2\msvc2019_64\bin) in to `PATH` environment variable.
- [AMCAX Kernal](https://amcax.net/) 3.6.1
### Steps
- Set environment variables
**CMAKE\_PREFIX\_PATH=%YOUR\_QT\_INSTALL\_DIR%\\msvc2019%YOUR\_CPU\_ARCH%\\lib\\cmake**
For example:
`d:\\qt\\5.15.2\\msvc2019\_64\\lib\\cmake\\`
- Add AMCAX Kernel library
Unzip the library and put it under the root folder of this project. The folder structure should look like this:
```text
Amcax-Daemon
|----------AMCAX
|----------|----------include
|----------|----------lib
|----------|----------bin
|----------Resources
|----------Src
|----------third_party
|----------...
|----------CMakeLists.txt
```
- Open "Visual Studio 2019" and choose `continue without code`, navigate to `File` -> `Open` -> `CMake...` and then open the `CMakeLists.txt` file of this project.
- Build
- Copy the folders (`Debug` & `Release`) in AMCAX/bin into your project's output folder.
- Run AmcaxDaemon.exe and have fun!
## Tutorial
### Code Structure Overview
The code structure for AMCAX daemon looks like below.
<p align="center">
<picture>
<img width="613" alt="code_structure" src="https://github.com/amcax-kernel/amcax-daemon/assets/150573876/9c2f9a30-537d-4fe5-9c31-3546455b8392">
</picture>
<p align="center">Figure 3 Code Structure</p>
</p>
It's built upon AMCAX Kernel SDK and OpenGL. From bottom to top:
- [`Operation`](./Src/Operation) folder includes helper classes that can call kernel SDK to create the underlying geometry objects, [`ObjectDraw`](./Src/ObjectDraw) folder includes classes that are used to draw a target object using OpenGL;
- [`Object`](./Src/Object) folder includes the wrapper classes for the kernel's underlying geometry objects, these wrapper classes leverage [`Operation`](./Src/Operation) & [`ObjectDraw`](./Src/ObjectDraw) to support object operation and rendering.
- [`Core`](./Src/Core) folder includes a `DataManager` which manages all the objects that are currently created, `UnRedoHandler` which supports undo/redo operations, `ACAMFile` which supports object persistence to file.
- [`Windows`](./Src/Windows) folder contains classes for user interaction and currently leverages libqglviewer for camera/projection related coordinate axes transform.
### Create Geometry Objects
Using AMCAX Kernel to create an object is as simple as:
```cpp
std::vector<AMCAX::Point3> point_list;
// TODO: prepare the points
std::list<AMCAX::TopoShape> edges;
for (int i = 1; i < point_list.size(); ++i)
{
edges.push_back(AMCAX::MakeEdge(point_list[i-1], point_list[i]));
}
edges.push_back(AMCAX::MakeEdge(point_list.back(), (point_list.front())));
AMCAX::MakeWire mkw;
mkw.Add(edges);
AMCAX::TopoShape result = AMCAX::MakeFace(mkw.Wire());
// TODO: save the result for future use.
```
### Modify Geometry Objects
An example of using AMCAX kernel to fuse multiple objects can be found in the class MultOperate_BoolFuse. It is as simple as:
```cpp
std::vector<AMCAX::TopoShape> shapeVector;
// TODO: prepare the shapes
AMCAX::TopoShape resultShape = AMCAX::BoolBRepFuse(shapeVector[0], shapeVector[1]);
for (int i = 2; i < shapeVector.size(); ++i)
{
resultShape = AMCAX::BoolBRepFuse(resultShape, shapeVector[i]);
}
```
More examples can be found [`Operation`](./Src/Operation) folder.
### Persistent Geometry Objects
The basic idea is to use AMCAD::TopoCompound and AMCAD::TopoBuilder to compound the objects you want to persistent, and then save them to ABR file. Code snippet as below:
```cpp
std::string fileName = "foo.abr";
std::vector<AMCAX::TopoShape> shapeVector;
//TODO. Prepare the shapes
AMCAX::TopoCompound comp;
AMCAX::TopoBuilder build;
build.MakeCompound(comp);
std::vector<AMCAX::TopoShape>::iterator it = shapeVector.begin();
for (; it != shapeVector.end(); it++)
{
build.Add(comp, *it);
}
AMCAX::ShapeTool::Write(comp, fileName);
```
Refer to [`ACAMCoreFile.cpp`](./Src/Core/ACAMCoreFile.cpp) for more details.
## Known Issues
- `Undo/Redo` is not currently supported for actions beyond creating/deleting objects. So if you create an object, move it and then delete it, and `undo` the delete operation, the restored object will not be placed at the moved position.
- Requires corresponding Debug/Release AMCAX kernel library when building, i.e, if you are building the AMCAX-Daemon debug version, you would need a debug version AMCAX kernel library. However, you could still debug AMCAX-Daemon code with the newly updated CMakeSettings which sets the configuration type as `RelWithDebInfo`.
- When import STEP file, the viewport needs manual zoom to make the objects show normally.
## License
AMCAX-Daemon uses dual licensing: it is freely available under the terms of the GNU Affero General Public License v3.0 (AGPLv3.0) for open source software development, while commercial applications can apply for a commercial license.
## Contact Us
Welcome to your feedback and contributions!
You can create Git issues here or join our [community](https://bbs.amcax.net/) (Chinese) to further participate into this project.
---
**Copyright © 2023 Hefei Jiushao Intelligent Technology Co., Ltd. All rights reserved.**