Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangechen committed Oct 22, 2024
2 parents 1dc871c + 73b8235 commit 6abd363
Show file tree
Hide file tree
Showing 150 changed files with 1,247 additions and 13,770 deletions.
44 changes: 28 additions & 16 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ project (chili-wasm)
set (CMAKE_CXX_STANDARD 17)
set (TARGET chili-wasm)
set (CMAKE_CONFIGURATION_TYPES Debug;Release)
set (CMAKE_NINJA_FORCE_RESPONSE_FILE 1 CACHE INTERNAL "")

get_filename_component(SOURCE_ROOT_DIR ${CMAKE_SOURCE_DIR} DIRECTORY)
set(CMAKE_INSTALL_PREFIX "${SOURCE_ROOT_DIR}/packages/chili-wasm/lib")

set (OcctModules
set (OcctToolkits
# FoundationClasses
TKernel TKMath
# ModelingData
Expand All @@ -20,20 +21,23 @@ set (OcctModules
# ApplicationFramework
TKCDF TKLCAF TKCAF TKStdL TKStd TKVCAF TKBin TKBinL TKBinXCAF
# DataExchange
TKDE TKXSBase TKDESTEP TKDEIGES TKDESTL TKDEVRML TKDEOBJ TKDEGLTF TKDEPLY TKXCAF TKRWMesh
TKDE TKXSBase TKXCAF TKDESTEP TKDEIGES
)

set (OcctUsedPackages)
foreach(toolkit ${OcctToolkits})
file (STRINGS build/occt/src/${toolkit}/PACKAGES OcctPackages)
list (APPEND OcctUsedPackages ${OcctPackages})
endforeach()
list (REMOVE_DUPLICATES OcctUsedPackages)

set (OcctSourceFolders)
set (OcctIncludeDirs)

foreach(module ${OcctModules})
file (STRINGS build/occt/src/${module}/PACKAGES OcctPackage)
foreach(package ${OcctPackage})
if (NOT package STREQUAL "")
list (APPEND OcctSourceFolders build/occt/src/${package}/*.c*)
list (APPEND OcctIncludeDirs build/occt/src/${package})
endif()
endforeach()
foreach(package ${OcctUsedPackages})
if (NOT package STREQUAL "")
list (APPEND OcctSourceFolders build/occt/src/${package}/*.c*)
list (APPEND OcctIncludeDirs build/occt/src/${package})
endif()
endforeach()

file (GLOB OcctSourceFiles ${OcctSourceFolders})
Expand All @@ -48,18 +52,27 @@ source_group ("Sources" FILES ${ChiliWasmSourceFiles})
source_group ("OCCT" FILES ${OcctSourceFiles})

if (${EMSCRIPTEN})
add_executable (${TARGET} ${ChiliWasmSourceFiles} ${OcctSourceFiles})

target_compile_options (${TARGET} PUBLIC
add_library(occt STATIC ${OcctSourceFiles})
target_include_directories (occt PUBLIC ${OcctIncludeDirs})
target_compile_options (occt PUBLIC
$<$<CONFIG:Release>:-O3>
$<$<CONFIG:Release>:-flto>
$<IF:$<CONFIG:Release>,-sDISABLE_EXCEPTION_CATCHING=1,-sDISABLE_EXCEPTION_CATCHING=0>
-DOCCT_NO_PLUGINS
)

add_executable (${TARGET} ${ChiliWasmSourceFiles})
target_include_directories (${TARGET} PUBLIC ${OcctIncludeDirs})
target_compile_options (${TARGET} PUBLIC
$<$<CONFIG:Release>:-O3>
$<$<CONFIG:Release>:-flto>
$<IF:$<CONFIG:Release>,-sDISABLE_EXCEPTION_CATCHING=1,-sDISABLE_EXCEPTION_CATCHING=0>
)
target_link_libraries(${TARGET} PUBLIC occt)
target_link_options (${TARGET} PUBLIC
$<IF:$<CONFIG:Release>,-O3,-O0>
$<$<CONFIG:Release>:-flto>
$<IF:$<CONFIG:Release>,-flto,-fno-lto>
$<IF:$<CONFIG:Release>,-sDISABLE_EXCEPTION_CATCHING=1,-sDISABLE_EXCEPTION_CATCHING=0>
-sMODULARIZE=1
-sEXPORT_ES6=1
Expand All @@ -69,9 +82,8 @@ if (${EMSCRIPTEN})
--emit-tsd "${TARGET}.d.ts"
)

target_include_directories (${TARGET} PUBLIC ${OcctIncludeDirs})

install(TARGETS ${TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.wasm DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.d.ts DESTINATION ${CMAKE_INSTALL_PREFIX})

endif ()
3 changes: 2 additions & 1 deletion cpp/src/shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class Shape {
return section.Shape();
}

static TopoDS_Shape sectionSP(const TopoDS_Shape& shape, const gp_Pln& pln) {
static TopoDS_Shape sectionSP(const TopoDS_Shape& shape, const Ax3& ax3) {
gp_Pln pln = Ax3::toPln(ax3);
BRepAlgoAPI_Section section(shape, pln);
return section.Shape();
}
Expand Down
30 changes: 1 addition & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chili3d",
"version": "0.3.0",
"version": "0.4-beta",
"description": "",
"author": "仙阁",
"scripts": {
Expand Down
3 changes: 1 addition & 2 deletions packages/chili-builder/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"name": "chili-builder",
"version": "0.3.0",
"version": "0.4-beta",
"description": "",
"main": "src/index.ts",
"devDependencies": {
"chili": "*",
"chili-three": "*",
"chili-occ": "*",
"chili-ui": "*",
"chili-wasm": "*"
}
Expand Down
50 changes: 28 additions & 22 deletions packages/chili-builder/src/appBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,9 @@ export class AppBuilder {
return this;
}

useOcc(): this {
useWasmOcc() {
this._inits.push(async () => {
Logger.info("initializing occ");

let occ = await import("chili-occ");
await occ.initMyOcc();
this._shapeFactory = new occ.ShapeFactory();
});
return this;
}

useNewOcc() {
this._inits.push(async () => {
Logger.info("initializing new occ");
Logger.info("initializing wasm occ");

let wasm = await import("chili-wasm");
await wasm.initWasm();
Expand All @@ -68,8 +57,10 @@ export class AppBuilder {
this._inits.push(async () => {
Logger.info("initializing MainWindow");

this.loadAdditionalI18n();

let ui = await import("chili-ui");
this._window = new ui.MainWindow();
this._window = new ui.MainWindow(await this.getRibbonTabs());
});
return this;
}
Expand All @@ -79,23 +70,33 @@ export class AppBuilder {
return this;
}

async getRibbonTabs() {
let defaultRibbon = await import("./ribbon");
return defaultRibbon.DefaultRibbon;
}

async build(): Promise<void> {
for (const init of this._inits) {
await init();
}
this.ensureNecessary();

Application.build(
let app = this.createApp();
this._window?.init(app);

this.loadAdditionalCommands();

Logger.info("Application build completed");
}

createApp() {
return new Application(
this._visualFactory!,
this._shapeFactory!,
this.getServices(),
this._storage!,
this._window,
this._window
);

this.loadAdditionalModule();

Logger.info("Application build completed");
}

private ensureNecessary() {
Expand All @@ -110,11 +111,16 @@ export class AppBuilder {
}
}

private loadAdditionalModule() {
private loadAdditionalI18n() {
for (const module of this._additionalModules) {
module.i18n().forEach((local) => {
I18n.combineTranslation(local.code as any, local.translation);
I18n.combineTranslation(local.code, local.translation);
});
}
}

private loadAdditionalCommands() {
for (const module of this._additionalModules) {
if (this._window) {
module.ribbonCommands().forEach((command) => {
this._window!.registerRibbonCommand(command.tabName, command.groupName, command.command);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import { CommandKeys, I18nKeys } from "chili-core";
import { RibbonTab } from "chili-core";

export type RibbonGroupProfile = {
groupName: I18nKeys;
items: (CommandKeys | CommandKeys[])[];
};

export type RibbonTabProfile = {
tabName: I18nKeys;
groups: RibbonGroupProfile[];
};

export const DefaultRibbon: RibbonTabProfile[] = [
export const DefaultRibbon: RibbonTab[] = [
{
tabName: "ribbon.tab.startup",
groups: [
Expand Down
2 changes: 1 addition & 1 deletion packages/chili-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chili-core",
"version": "0.3.0",
"version": "0.4-beta",
"description": "",
"main": "src/index.ts",
"devDependencies": {}
Expand Down
2 changes: 1 addition & 1 deletion packages/chili-core/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import { IVisual } from "./visual";
export interface IDocument extends IPropertyChanged, IDisposable, ISerialize {
name: string;
currentNode?: INodeLinkedList;
rootNode: INodeLinkedList;
readonly selection: ISelection;
readonly id: string;
readonly history: History;
readonly visual: IVisual;
readonly rootNode: INodeLinkedList;
readonly application: IApplication;
materials: ObservableCollection<Material>;
addNode(...nodes: INode[]): void;
Expand Down
4 changes: 2 additions & 2 deletions packages/chili-core/src/foundation/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class Binding<T extends IPropertyChanged = any> {
this.source.removePropertyChanged(this._onPropertyChanged);
}

private _onPropertyChanged = (property: keyof T) => {
private readonly _onPropertyChanged = (property: keyof T) => {
if (property === this.path && this._target) {
let element = this._target.element.deref();
if (element) {
Expand All @@ -66,6 +66,6 @@ export class Binding<T extends IPropertyChanged = any> {
if (!result.isOk) {
throw new Error(`Cannot convert value ${value}`);
}
return result.ok();
return result.value;
}
}
2 changes: 1 addition & 1 deletion packages/chili-core/src/foundation/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface ICollectionChanged {
}

export class ObservableCollection<T> implements ICollectionChanged, IDisposable {
private _callbacks: Set<(args: CollectionChangedArgs) => void> = new Set();
private readonly _callbacks: Set<(args: CollectionChangedArgs) => void> = new Set();
private _items: T[];

constructor(...items: T[]) {
Expand Down
4 changes: 2 additions & 2 deletions packages/chili-core/src/foundation/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export interface IHistoryRecord extends IDisposable {
}

export class History implements IDisposable {
private _undos: IHistoryRecord[] = [];
private _redos: IHistoryRecord[] = [];
private readonly _undos: IHistoryRecord[] = [];
private readonly _redos: IHistoryRecord[] = [];

disabled: boolean = false;
undoLimits: number = 50;
Expand Down
Loading

0 comments on commit 6abd363

Please sign in to comment.