Compare commits
14 Commits
master
..
1be782b88d
| Author | SHA1 | Date | |
|---|---|---|---|
| 1be782b88d | |||
| 3444e9e183 | |||
| fdd972b286 | |||
| 768eed2f39 | |||
| 41639882db | |||
| fa6e4662a6 | |||
| a7ad78e103 | |||
| 0798cd2a6c | |||
| ce6975cc44 | |||
| b9860f3de0 | |||
| 6e729183ef | |||
| d5d430e80d | |||
| 95b4db5191 | |||
| e2dfdf1600 |
+1
-23
@@ -28,33 +28,11 @@ endif()
|
|||||||
message(STATUS "OpenCASCADE_INCLUDE_DIRS: ${OpenCASCADE_INCLUDE_DIRS}")
|
message(STATUS "OpenCASCADE_INCLUDE_DIRS: ${OpenCASCADE_INCLUDE_DIRS}")
|
||||||
message(STATUS "OpenCASCADE_LIBRARIES: ${OpenCASCADE_LIBRARIES}")
|
message(STATUS "OpenCASCADE_LIBRARIES: ${OpenCASCADE_LIBRARIES}")
|
||||||
|
|
||||||
# Automatically find resource files and generate resources.qrc
|
|
||||||
set(GENERATED_QRC_FILE "${CMAKE_CURRENT_BINARY_DIR}/resources.qrc")
|
|
||||||
set(QRC_CONTENT "")
|
|
||||||
|
|
||||||
file(GLOB ICON_FILES "icons/*.svg")
|
|
||||||
string(APPEND QRC_CONTENT " <qresource prefix=\"/icons\">\n")
|
|
||||||
foreach(ICON_FILE IN LISTS ICON_FILES)
|
|
||||||
get_filename_component(ICON_ALIAS ${ICON_FILE} NAME)
|
|
||||||
string(APPEND QRC_CONTENT " <file alias=\"${ICON_ALIAS}\">${ICON_FILE}</file>\n")
|
|
||||||
endforeach()
|
|
||||||
string(APPEND QRC_CONTENT " </qresource>\n")
|
|
||||||
|
|
||||||
file(GLOB SHADER_FILES "src/shaders/*")
|
|
||||||
string(APPEND QRC_CONTENT " <qresource prefix=\"/shaders\">\n")
|
|
||||||
foreach(SHADER_FILE IN LISTS SHADER_FILES)
|
|
||||||
get_filename_component(SHADER_ALIAS ${SHADER_FILE} NAME)
|
|
||||||
string(APPEND QRC_CONTENT " <file alias=\"${SHADER_ALIAS}\">${SHADER_FILE}</file>\n")
|
|
||||||
endforeach()
|
|
||||||
string(APPEND QRC_CONTENT " </qresource>\n")
|
|
||||||
|
|
||||||
file(WRITE ${GENERATED_QRC_FILE} "<RCC>\n${QRC_CONTENT}</RCC>\n")
|
|
||||||
|
|
||||||
file(GLOB SOURCES "src/*.cpp")
|
file(GLOB SOURCES "src/*.cpp")
|
||||||
|
|
||||||
add_executable(OpenCAD
|
add_executable(OpenCAD
|
||||||
${SOURCES}
|
${SOURCES}
|
||||||
${GENERATED_QRC_FILE}
|
resources.qrc
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(OpenCAD SYSTEM PRIVATE ${OpenCASCADE_INCLUDE_DIRS})
|
target_include_directories(OpenCAD SYSTEM PRIVATE ${OpenCASCADE_INCLUDE_DIRS})
|
||||||
|
|||||||
-674
@@ -1,674 +0,0 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
|
||||||
or can get the source code. And you must show them these terms so they
|
|
||||||
know their rights.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
|
||||||
that there is no warranty for this free software. For both users' and
|
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
|
||||||
authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
{{ project }} Copyright (C) {{ year }} {{ organization }}
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
<http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
On Debian 12:
|
On Debian 12:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ sudo apt install cmake qt6-base-dev qt6-svg-dev libtbb-dev libfontconfig1-dev
|
$ sudo apt install cmake qt6-base-dev qt6-svg-dev libtbb-dev
|
||||||
$ sudo apt install libocct-foundation-dev libocct-modeling-data-dev libocct-modeling-algorithms-dev libocct-visualization-dev
|
$ sudo apt install libocct-foundation-dev libocct-modeling-data-dev libocct-modeling-algorithms-dev libocct-visualization-dev
|
||||||
|
|
||||||
$ mkdir build
|
$ mkdir build
|
||||||
@@ -17,12 +17,3 @@ $ make
|
|||||||
|
|
||||||
$ ./OpenCAD
|
$ ./OpenCAD
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
This program is free and open-source software licensed under the GNU GPLv3 (or later). Please see the `LICENSE.txt` file for details.
|
|
||||||
|
|
||||||
That means you have the right to study, change, and distribute the software and source code to anyone and for any purpose as long as you grant the same rights when distributing it.
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>icons/create-sketch.svg</file>
|
||||||
|
<file>icons/extrude.svg</file>
|
||||||
|
<file>icons/line.svg</file>
|
||||||
|
<file>icons/rectangle.svg</file>
|
||||||
|
<file>icons/circle.svg</file>
|
||||||
|
<file>icons/save-sketch.svg</file>
|
||||||
|
<file>icons/cursor.svg</file>
|
||||||
|
<file>icons/home.svg</file>
|
||||||
|
</qresource>
|
||||||
|
<qresource prefix="/shaders">
|
||||||
|
<file alias="simple.vert">src/shaders/simple.vert</file>
|
||||||
|
<file alias="simple.frag">src/shaders/simple.frag</file>
|
||||||
|
<file alias="texture.vert">src/shaders/texture.vert</file>
|
||||||
|
<file alias="texture.frag">src/shaders/texture.frag</file>
|
||||||
|
<file alias="lit.vert">src/shaders/lit.vert</file>
|
||||||
|
<file alias="lit.frag">src/shaders/lit.frag</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "ApplicationController.h"
|
#include "ApplicationController.h"
|
||||||
#include "Document.h"
|
#include "Document.h"
|
||||||
#include "SketchFeature.h"
|
#include "SketchFeature.h"
|
||||||
@@ -13,16 +6,6 @@
|
|||||||
#include "SketchCircle.h"
|
#include "SketchCircle.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
|
||||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
|
||||||
#include <BRepBuilderAPI_MakeWire.hxx>
|
|
||||||
#include <GC_MakeSegment.hxx>
|
|
||||||
#include <ElCLib.hxx>
|
|
||||||
#include <gp_Ax2.hxx>
|
|
||||||
#include <gp_Circ.hxx>
|
|
||||||
#include <gp_Dir.hxx>
|
|
||||||
#include <gp_Vec.hxx>
|
|
||||||
#include <gp_Pnt2d.hxx>
|
|
||||||
|
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@@ -127,12 +110,26 @@ void ApplicationController::beginSketchCreation()
|
|||||||
emit planeSelectionModeStarted();
|
emit planeSelectionModeStarted();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationController::onPlaneSelected(const gp_Ax2& plane)
|
void ApplicationController::onPlaneSelected(ViewportWidget::SketchPlane plane)
|
||||||
{
|
{
|
||||||
auto feature = new SketchFeature("Sketch");
|
auto feature = new SketchFeature("Sketch");
|
||||||
m_activeSketch = feature;
|
m_activeSketch = feature;
|
||||||
|
|
||||||
feature->setPlane(plane);
|
switch (plane) {
|
||||||
|
case ViewportWidget::SketchPlane::XY:
|
||||||
|
feature->setPlane(SketchFeature::SketchPlane::XY);
|
||||||
|
break;
|
||||||
|
case ViewportWidget::SketchPlane::XZ:
|
||||||
|
feature->setPlane(SketchFeature::SketchPlane::XZ);
|
||||||
|
break;
|
||||||
|
case ViewportWidget::SketchPlane::YZ:
|
||||||
|
feature->setPlane(SketchFeature::SketchPlane::YZ);
|
||||||
|
break;
|
||||||
|
case ViewportWidget::SketchPlane::NONE:
|
||||||
|
delete feature;
|
||||||
|
m_activeSketch = nullptr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_document->addFeature(feature);
|
m_document->addFeature(feature);
|
||||||
emit sketchModeStarted(plane);
|
emit sketchModeStarted(plane);
|
||||||
@@ -142,10 +139,6 @@ void ApplicationController::addLine(const gp_Pnt& start, const gp_Pnt& end)
|
|||||||
{
|
{
|
||||||
if (m_activeSketch) {
|
if (m_activeSketch) {
|
||||||
m_activeSketch->addObject(new SketchLine(start, end));
|
m_activeSketch->addObject(new SketchLine(start, end));
|
||||||
|
|
||||||
Handle(Geom_TrimmedCurve) segment = GC_MakeSegment(start, end);
|
|
||||||
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(segment);
|
|
||||||
m_activeSketch->addShape(edge);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,27 +146,6 @@ void ApplicationController::addRectangle(const gp_Pnt& corner1, const gp_Pnt& co
|
|||||||
{
|
{
|
||||||
if (m_activeSketch) {
|
if (m_activeSketch) {
|
||||||
m_activeSketch->addObject(new SketchRectangle(corner1, corner2));
|
m_activeSketch->addObject(new SketchRectangle(corner1, corner2));
|
||||||
|
|
||||||
const auto& plane = m_activeSketch->plane();
|
|
||||||
|
|
||||||
gp_Pnt2d p1_2d(gp_Vec(plane.Location(), corner1).Dot(plane.XDirection()), gp_Vec(plane.Location(), corner1).Dot(plane.YDirection()));
|
|
||||||
gp_Pnt2d p3_2d(gp_Vec(plane.Location(), corner2).Dot(plane.XDirection()), gp_Vec(plane.Location(), corner2).Dot(plane.YDirection()));
|
|
||||||
|
|
||||||
gp_Pnt2d p2_2d(p3_2d.X(), p1_2d.Y());
|
|
||||||
gp_Pnt2d p4_2d(p1_2d.X(), p3_2d.Y());
|
|
||||||
|
|
||||||
gp_Pnt p2_3d = ElCLib::To3d(plane, p2_2d);
|
|
||||||
gp_Pnt p4_3d = ElCLib::To3d(plane, p4_2d);
|
|
||||||
|
|
||||||
TopoDS_Edge e1 = BRepBuilderAPI_MakeEdge(corner1, p2_3d);
|
|
||||||
TopoDS_Edge e2 = BRepBuilderAPI_MakeEdge(p2_3d, corner2);
|
|
||||||
TopoDS_Edge e3 = BRepBuilderAPI_MakeEdge(corner2, p4_3d);
|
|
||||||
TopoDS_Edge e4 = BRepBuilderAPI_MakeEdge(p4_3d, corner1);
|
|
||||||
|
|
||||||
BRepBuilderAPI_MakeWire wireMaker(e1, e2, e3, e4);
|
|
||||||
if (wireMaker.IsDone()) {
|
|
||||||
m_activeSketch->addShape(wireMaker.Shape());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,18 +153,14 @@ void ApplicationController::addCircle(const gp_Pnt& center, double radius)
|
|||||||
{
|
{
|
||||||
if (m_activeSketch) {
|
if (m_activeSketch) {
|
||||||
m_activeSketch->addObject(new SketchCircle(center, radius));
|
m_activeSketch->addObject(new SketchCircle(center, radius));
|
||||||
|
|
||||||
const auto& sketchPlane = m_activeSketch->plane();
|
|
||||||
gp_Ax2 axis(center, sketchPlane.Direction());
|
|
||||||
|
|
||||||
gp_Circ circle(axis, radius);
|
|
||||||
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(circle);
|
|
||||||
m_activeSketch->addShape(edge);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationController::endSketch()
|
void ApplicationController::endSketch()
|
||||||
{
|
{
|
||||||
|
if (m_activeSketch) {
|
||||||
|
m_activeSketch->buildShape();
|
||||||
|
}
|
||||||
m_activeSketch = nullptr;
|
m_activeSketch = nullptr;
|
||||||
setActiveTool(ToolType::None);
|
setActiveTool(ToolType::None);
|
||||||
emit sketchModeEnded();
|
emit sketchModeEnded();
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef APPLICATIONCONTROLLER_H
|
#ifndef APPLICATIONCONTROLLER_H
|
||||||
#define APPLICATIONCONTROLLER_H
|
#define APPLICATIONCONTROLLER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include "ViewportWidget.h" // For SketchPlane enum
|
||||||
#include <gp_Pnt.hxx>
|
#include <gp_Pnt.hxx>
|
||||||
#include <gp_Ax2.hxx>
|
|
||||||
|
|
||||||
class Document;
|
class Document;
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
@@ -47,12 +40,12 @@ public slots:
|
|||||||
bool saveDocumentAs();
|
bool saveDocumentAs();
|
||||||
|
|
||||||
void beginSketchCreation();
|
void beginSketchCreation();
|
||||||
void onPlaneSelected(const gp_Ax2& plane);
|
void onPlaneSelected(ViewportWidget::SketchPlane plane);
|
||||||
void endSketch();
|
void endSketch();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void planeSelectionModeStarted();
|
void planeSelectionModeStarted();
|
||||||
void sketchModeStarted(const gp_Ax2& plane);
|
void sketchModeStarted(ViewportWidget::SketchPlane plane);
|
||||||
void sketchModeEnded();
|
void sketchModeEnded();
|
||||||
void currentFileChanged(const QString& path);
|
void currentFileChanged(const QString& path);
|
||||||
void activeToolChanged(ToolType tool);
|
void activeToolChanged(ToolType tool);
|
||||||
|
|||||||
+25
-51
@@ -1,13 +1,5 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include <gp_Ax2.hxx>
|
#include "ViewportWidget.h"
|
||||||
#include <gp_Dir.hxx>
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
@@ -75,7 +67,6 @@ void Camera::wheelEvent(QWheelEvent* event, const QVector3D& worldPos)
|
|||||||
QMatrix4x4 rotation;
|
QMatrix4x4 rotation;
|
||||||
rotation.rotate(m_xRot / 16.0f, 1, 0, 0);
|
rotation.rotate(m_xRot / 16.0f, 1, 0, 0);
|
||||||
rotation.rotate(m_yRot / 16.0f, 0, 1, 0);
|
rotation.rotate(m_yRot / 16.0f, 0, 1, 0);
|
||||||
rotation.rotate(-90.0f, 1, 0, 0);
|
|
||||||
QVector3D p_camera = rotation.map(worldPos);
|
QVector3D p_camera = rotation.map(worldPos);
|
||||||
|
|
||||||
if (std::abs(p_camera.z() + oldZoom) < 1e-6) {
|
if (std::abs(p_camera.z() + oldZoom) < 1e-6) {
|
||||||
@@ -99,20 +90,14 @@ QMatrix4x4 Camera::modelViewMatrix() const
|
|||||||
QMatrix4x4 model;
|
QMatrix4x4 model;
|
||||||
model.translate(m_panX, m_panY, m_zoom);
|
model.translate(m_panX, m_panY, m_zoom);
|
||||||
|
|
||||||
QMatrix4x4 zup_rotation;
|
|
||||||
zup_rotation.rotate(-90.0f, 1, 0, 0);
|
|
||||||
QVector3D pivot_yup = zup_rotation.map(m_rotationPivot);
|
|
||||||
|
|
||||||
if (m_isRotating) {
|
if (m_isRotating) {
|
||||||
model.translate(pivot_yup);
|
model.translate(m_rotationPivot);
|
||||||
}
|
}
|
||||||
model.rotate(m_xRot / 16.0f, 1, 0, 0);
|
model.rotate(m_xRot / 16.0f, 1, 0, 0);
|
||||||
model.rotate(m_yRot / 16.0f, 0, 1, 0);
|
model.rotate(m_yRot / 16.0f, 0, 1, 0);
|
||||||
if (m_isRotating) {
|
if (m_isRotating) {
|
||||||
model.translate(-pivot_yup);
|
model.translate(-m_rotationPivot);
|
||||||
}
|
}
|
||||||
|
|
||||||
model.rotate(-90.0f, 1, 0, 0); // For Z-up system
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,28 +188,25 @@ void Camera::restoreState()
|
|||||||
setZoom(m_savedZoom);
|
setZoom(m_savedZoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::animateToPlaneView(const gp_Ax2& plane)
|
void Camera::animateToPlaneView(int plane)
|
||||||
{
|
{
|
||||||
const auto& normal = plane.Direction();
|
float targetXRot = xRotation();
|
||||||
QVector3D n(normal.X(), normal.Y(), normal.Z());
|
float targetYRot = yRotation();
|
||||||
QVector3D d;
|
switch (static_cast<ViewportWidget::SketchPlane>(plane)) {
|
||||||
|
case ViewportWidget::SketchPlane::XY: // Top view
|
||||||
// This logic preserves the quirky view directions of the original implementation.
|
targetXRot = 90 * 16;
|
||||||
// For XZ-like planes (normal is mostly along Y), the view is aligned WITH the plane normal.
|
targetYRot = 0;
|
||||||
// For other planes, it's aligned AGAINST the normal.
|
break;
|
||||||
if (qAbs(n.y()) > 0.99) {
|
case ViewportWidget::SketchPlane::XZ: // Front view
|
||||||
d = n;
|
targetXRot = 0;
|
||||||
} else {
|
targetYRot = 0;
|
||||||
d = -n;
|
break;
|
||||||
}
|
case ViewportWidget::SketchPlane::YZ: // Right view
|
||||||
|
targetXRot = 0;
|
||||||
float targetXRot = qRadiansToDegrees(asin(-d.z())) * 16.0f;
|
targetYRot = -90 * 16;
|
||||||
float targetYRot;
|
break;
|
||||||
|
case ViewportWidget::SketchPlane::NONE:
|
||||||
if (qAbs(d.z()) > 0.9999) { // Top/bottom-like view, Y rotation is arbitrary
|
break;
|
||||||
targetYRot = 0; // Set to 0 for stability
|
|
||||||
} else {
|
|
||||||
targetYRot = qRadiansToDegrees(atan2(d.x(), d.y())) * 16.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* animGroup = new QParallelAnimationGroup(this);
|
auto* animGroup = new QParallelAnimationGroup(this);
|
||||||
@@ -359,16 +341,12 @@ void Camera::startRotation(const QVector3D& pivot)
|
|||||||
}
|
}
|
||||||
m_stableZoom = m_zoom;
|
m_stableZoom = m_zoom;
|
||||||
|
|
||||||
QMatrix4x4 zup_rotation;
|
|
||||||
zup_rotation.rotate(-90.0f, 1, 0, 0);
|
|
||||||
QVector3D pivot_yup = zup_rotation.map(m_rotationPivot);
|
|
||||||
|
|
||||||
QMatrix4x4 rotation;
|
QMatrix4x4 rotation;
|
||||||
rotation.rotate(m_xRot / 16.0f, 1, 0, 0);
|
rotation.rotate(m_xRot / 16.0f, 1, 0, 0);
|
||||||
rotation.rotate(m_yRot / 16.0f, 0, 1, 0);
|
rotation.rotate(m_yRot / 16.0f, 0, 1, 0);
|
||||||
|
|
||||||
QVector3D p_rotated = rotation.map(pivot_yup);
|
QVector3D p_rotated = rotation.map(m_rotationPivot);
|
||||||
QVector3D p_diff = p_rotated - pivot_yup;
|
QVector3D p_diff = p_rotated - m_rotationPivot;
|
||||||
|
|
||||||
setPanX(m_panX + p_diff.x());
|
setPanX(m_panX + p_diff.x());
|
||||||
setPanY(m_panY + p_diff.y());
|
setPanY(m_panY + p_diff.y());
|
||||||
@@ -383,16 +361,12 @@ void Camera::stopRotation()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMatrix4x4 zup_rotation;
|
|
||||||
zup_rotation.rotate(-90.0f, 1, 0, 0);
|
|
||||||
QVector3D pivot_yup = zup_rotation.map(m_rotationPivot);
|
|
||||||
|
|
||||||
QMatrix4x4 rotation;
|
QMatrix4x4 rotation;
|
||||||
rotation.rotate(m_xRot / 16.0f, 1, 0, 0);
|
rotation.rotate(m_xRot / 16.0f, 1, 0, 0);
|
||||||
rotation.rotate(m_yRot / 16.0f, 0, 1, 0);
|
rotation.rotate(m_yRot / 16.0f, 0, 1, 0);
|
||||||
|
|
||||||
QVector3D p_rotated = rotation.map(pivot_yup);
|
QVector3D p_rotated = rotation.map(m_rotationPivot);
|
||||||
QVector3D p_diff = p_rotated - pivot_yup;
|
QVector3D p_diff = p_rotated - m_rotationPivot;
|
||||||
|
|
||||||
setPanX(m_panX - p_diff.x());
|
setPanX(m_panX - p_diff.x());
|
||||||
setPanY(m_panY - p_diff.y());
|
setPanY(m_panY - p_diff.y());
|
||||||
|
|||||||
+1
-10
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef CAMERA_H
|
#ifndef CAMERA_H
|
||||||
#define CAMERA_H
|
#define CAMERA_H
|
||||||
|
|
||||||
@@ -14,8 +7,6 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
|
|
||||||
#include <gp_Ax2.hxx>
|
|
||||||
|
|
||||||
class Camera : public QObject
|
class Camera : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -48,7 +39,7 @@ public:
|
|||||||
void saveState();
|
void saveState();
|
||||||
void restoreState();
|
void restoreState();
|
||||||
|
|
||||||
void animateToPlaneView(const gp_Ax2& plane);
|
void animateToPlaneView(int plane);
|
||||||
void animateRestoreState();
|
void animateRestoreState();
|
||||||
void animateToHomeView();
|
void animateToHomeView();
|
||||||
|
|
||||||
|
|||||||
+131
-132
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "CircleTool.h"
|
#include "CircleTool.h"
|
||||||
#include "ViewportWidget.h"
|
#include "ViewportWidget.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
@@ -15,10 +8,6 @@
|
|||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <optional>
|
|
||||||
#include <gp_Ax2.hxx>
|
|
||||||
#include <gp_Pnt2d.hxx>
|
|
||||||
#include <ElCLib.hxx>
|
|
||||||
|
|
||||||
CircleTool::CircleTool(ViewportWidget* viewport)
|
CircleTool::CircleTool(ViewportWidget* viewport)
|
||||||
: SketchTool(viewport)
|
: SketchTool(viewport)
|
||||||
@@ -39,18 +28,14 @@ void CircleTool::activate()
|
|||||||
|
|
||||||
void CircleTool::mousePressEvent(QMouseEvent *event)
|
void CircleTool::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
|
||||||
if (!currentPlaneOpt) return;
|
|
||||||
const auto& plane = currentPlaneOpt.value();
|
|
||||||
|
|
||||||
gp_Pnt p;
|
gp_Pnt p;
|
||||||
if (!m_isDefining) {
|
if (!m_isDefining) {
|
||||||
if (m_viewport->isSnappingOrigin()) {
|
if (m_viewport->isSnappingOrigin()) {
|
||||||
p = plane.Location();
|
p.SetCoord(0, 0, 0);
|
||||||
} else if (m_viewport->isSnappingVertex()) {
|
} else if (m_viewport->isSnappingVertex()) {
|
||||||
p = m_viewport->snapVertex();
|
p = m_viewport->snapVertex();
|
||||||
} else {
|
} else {
|
||||||
QVector3D worldPos = m_viewport->unproject(event->pos(), plane);
|
QVector3D worldPos = m_viewport->unproject(event->pos(), m_viewport->currentPlane());
|
||||||
p.SetCoord(worldPos.x(), worldPos.y(), worldPos.z());
|
p.SetCoord(worldPos.x(), worldPos.y(), worldPos.z());
|
||||||
}
|
}
|
||||||
m_centerPoint = p;
|
m_centerPoint = p;
|
||||||
@@ -78,22 +63,24 @@ void CircleTool::mousePressEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (diameterFromInput) {
|
if (diameterFromInput) {
|
||||||
QVector3D mousePos = m_viewport->unproject(event->pos(), plane);
|
QVector3D mousePos = m_viewport->unproject(event->pos(), m_viewport->currentPlane());
|
||||||
QVector3D mouseDir = mousePos - centerPos;
|
QVector3D mouseDir = mousePos - centerPos;
|
||||||
if (mouseDir.lengthSquared() < 1e-9) {
|
if (mouseDir.lengthSquared() < 1e-9) {
|
||||||
const auto& xDir = plane.XDirection();
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY || m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
mouseDir = QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
mouseDir = QVector3D(1, 0, 0);
|
||||||
|
} else { // YZ
|
||||||
|
mouseDir = QVector3D(0, 1, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
double radius = inputDiameter / 2.0;
|
double radius = inputDiameter / 2.0;
|
||||||
worldPos = centerPos + mouseDir.normalized() * radius;
|
worldPos = centerPos + mouseDir.normalized() * radius;
|
||||||
} else {
|
} else {
|
||||||
if (m_viewport->isSnappingOrigin()) {
|
if (m_viewport->isSnappingOrigin()) {
|
||||||
const auto& origin = plane.Location();
|
worldPos.setX(0); worldPos.setY(0); worldPos.setZ(0);
|
||||||
worldPos.setX(origin.X()); worldPos.setY(origin.Y()); worldPos.setZ(origin.Z());
|
|
||||||
} else if (m_viewport->isSnappingVertex()) {
|
} else if (m_viewport->isSnappingVertex()) {
|
||||||
worldPos = QVector3D(m_viewport->snapVertex().X(), m_viewport->snapVertex().Y(), m_viewport->snapVertex().Z());
|
worldPos = QVector3D(m_viewport->snapVertex().X(), m_viewport->snapVertex().Y(), m_viewport->snapVertex().Z());
|
||||||
} else {
|
} else {
|
||||||
worldPos = m_viewport->unproject(event->pos(), plane);
|
worldPos = m_viewport->unproject(event->pos(), m_viewport->currentPlane());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.SetCoord(worldPos.x(), worldPos.y(), worldPos.z());
|
p.SetCoord(worldPos.x(), worldPos.y(), worldPos.z());
|
||||||
@@ -109,10 +96,6 @@ void CircleTool::mouseMoveEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
void CircleTool::finalizeCreation()
|
void CircleTool::finalizeCreation()
|
||||||
{
|
{
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
|
||||||
if (!currentPlaneOpt) return;
|
|
||||||
const auto& plane = currentPlaneOpt.value();
|
|
||||||
|
|
||||||
QVector3D worldPos;
|
QVector3D worldPos;
|
||||||
QVector3D centerPos(m_centerPoint.X(), m_centerPoint.Y(), m_centerPoint.Z());
|
QVector3D centerPos(m_centerPoint.X(), m_centerPoint.Y(), m_centerPoint.Z());
|
||||||
|
|
||||||
@@ -127,16 +110,19 @@ void CircleTool::finalizeCreation()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (diameterFromInput) {
|
if (diameterFromInput) {
|
||||||
QVector3D mousePos = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
QVector3D mousePos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
QVector3D mouseDir = mousePos - centerPos;
|
QVector3D mouseDir = mousePos - centerPos;
|
||||||
if (mouseDir.lengthSquared() < 1e-9) {
|
if (mouseDir.lengthSquared() < 1e-9) {
|
||||||
const auto& xDir = plane.XDirection();
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY || m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
mouseDir = QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
mouseDir = QVector3D(1, 0, 0);
|
||||||
|
} else { // YZ
|
||||||
|
mouseDir = QVector3D(0, 1, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
double radius = inputDiameter / 2.0;
|
double radius = inputDiameter / 2.0;
|
||||||
worldPos = centerPos + mouseDir.normalized() * radius;
|
worldPos = centerPos + mouseDir.normalized() * radius;
|
||||||
} else {
|
} else {
|
||||||
worldPos = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
worldPos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
}
|
}
|
||||||
|
|
||||||
gp_Pnt p;
|
gp_Pnt p;
|
||||||
@@ -148,121 +134,134 @@ void CircleTool::finalizeCreation()
|
|||||||
|
|
||||||
void CircleTool::paintGL()
|
void CircleTool::paintGL()
|
||||||
{
|
{
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
if (m_isDefining) {
|
||||||
if (!m_isDefining || !currentPlaneOpt) return;
|
QVector<GLfloat> vertices;
|
||||||
const auto& plane = currentPlaneOpt.value();
|
QVector3D worldPos;
|
||||||
|
QVector3D centerPos(m_centerPoint.X(), m_centerPoint.Y(), m_centerPoint.Z());
|
||||||
|
|
||||||
QVector<GLfloat> vertices;
|
QString diameterInput = m_viewport->property("diameterInput").toString();
|
||||||
QVector3D worldPos;
|
bool diameterFromInput = false;
|
||||||
QVector3D centerPos(m_centerPoint.X(), m_centerPoint.Y(), m_centerPoint.Z());
|
double inputDiameter = 0;
|
||||||
|
|
||||||
QString diameterInput = m_viewport->property("diameterInput").toString();
|
if (!diameterInput.isEmpty()) {
|
||||||
bool diameterFromInput = false;
|
bool ok;
|
||||||
double inputDiameter = 0;
|
inputDiameter = diameterInput.toDouble(&ok);
|
||||||
|
if (ok) diameterFromInput = true;
|
||||||
if (!diameterInput.isEmpty()) {
|
|
||||||
bool ok;
|
|
||||||
inputDiameter = diameterInput.toDouble(&ok);
|
|
||||||
if (ok) diameterFromInput = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVector3D mousePos = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
|
||||||
|
|
||||||
double radius;
|
|
||||||
if (diameterFromInput) {
|
|
||||||
radius = inputDiameter / 2.0;
|
|
||||||
} else {
|
|
||||||
worldPos = mousePos;
|
|
||||||
if (m_viewport->isSnappingOrigin()) {
|
|
||||||
const auto& origin = plane.Location();
|
|
||||||
worldPos.setX(origin.X()); worldPos.setY(origin.Y()); worldPos.setZ(origin.Z());
|
|
||||||
} else if (m_viewport->isSnappingVertex()) {
|
|
||||||
worldPos.setX(m_viewport->snapVertex().X()); worldPos.setY(m_viewport->snapVertex().Y()); worldPos.setZ(m_viewport->snapVertex().Z());
|
|
||||||
}
|
}
|
||||||
radius = (worldPos - centerPos).length();
|
|
||||||
|
QVector3D mousePos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
|
|
||||||
|
double radius;
|
||||||
|
if (diameterFromInput) {
|
||||||
|
radius = inputDiameter / 2.0;
|
||||||
|
} else {
|
||||||
|
worldPos = mousePos;
|
||||||
|
if (m_viewport->isSnappingOrigin()) {
|
||||||
|
worldPos.setX(0); worldPos.setY(0); worldPos.setZ(0);
|
||||||
|
} else if (m_viewport->isSnappingVertex()) {
|
||||||
|
worldPos.setX(m_viewport->snapVertex().X()); worldPos.setY(m_viewport->snapVertex().Y()); worldPos.setZ(m_viewport->snapVertex().Z());
|
||||||
|
}
|
||||||
|
radius = (worldPos - centerPos).length();
|
||||||
|
}
|
||||||
|
|
||||||
|
const int segments = 64;
|
||||||
|
for (int i = 0; i < segments; ++i) {
|
||||||
|
double angle1 = i * 2.0 * M_PI / segments;
|
||||||
|
double angle2 = (i + 1) * 2.0 * M_PI / segments;
|
||||||
|
|
||||||
|
QVector3D p1, p2;
|
||||||
|
|
||||||
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
|
p1.setX(centerPos.x() + radius * qCos(angle1));
|
||||||
|
p1.setY(centerPos.y());
|
||||||
|
p1.setZ(centerPos.z() + radius * qSin(angle1));
|
||||||
|
p2.setX(centerPos.x() + radius * qCos(angle2));
|
||||||
|
p2.setY(centerPos.y());
|
||||||
|
p2.setZ(centerPos.z() + radius * qSin(angle2));
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
|
p1.setX(centerPos.x() + radius * qCos(angle1));
|
||||||
|
p1.setY(centerPos.y() + radius * qSin(angle1));
|
||||||
|
p1.setZ(centerPos.z());
|
||||||
|
p2.setX(centerPos.x() + radius * qCos(angle2));
|
||||||
|
p2.setY(centerPos.y() + radius * qSin(angle2));
|
||||||
|
p2.setZ(centerPos.z());
|
||||||
|
} else { // YZ
|
||||||
|
p1.setX(centerPos.x());
|
||||||
|
p1.setY(centerPos.y() + radius * qCos(angle1));
|
||||||
|
p1.setZ(centerPos.z() + radius * qSin(angle1));
|
||||||
|
p2.setX(centerPos.x());
|
||||||
|
p2.setY(centerPos.y() + radius * qCos(angle2));
|
||||||
|
p2.setZ(centerPos.z() + radius * qSin(angle2));
|
||||||
|
}
|
||||||
|
vertices << p1.x() << p1.y() << p1.z();
|
||||||
|
vertices << p2.x() << p2.y() << p2.z();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_viewport->shaderProgram()->setUniformValue(m_viewport->colorLoc(), QVector4D(1.0f, 1.0f, 0.0f, 1.0f));
|
||||||
|
m_viewport->vbo().bind();
|
||||||
|
m_viewport->vbo().allocate(vertices.constData(), vertices.size() * sizeof(GLfloat));
|
||||||
|
glDrawArrays(GL_LINES, 0, segments * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int segments = 64;
|
|
||||||
const auto& xDir = plane.XDirection();
|
|
||||||
const auto& yDir = plane.YDirection();
|
|
||||||
QVector3D u_axis(xDir.X(), xDir.Y(), xDir.Z());
|
|
||||||
QVector3D v_axis(yDir.X(), yDir.Y(), yDir.Z());
|
|
||||||
|
|
||||||
for (int i = 0; i < segments; ++i) {
|
|
||||||
double angle1 = i * 2.0 * M_PI / segments;
|
|
||||||
double angle2 = (i + 1) * 2.0 * M_PI / segments;
|
|
||||||
|
|
||||||
QVector3D p1 = centerPos + radius * (qCos(angle1) * u_axis + qSin(angle1) * v_axis);
|
|
||||||
QVector3D p2 = centerPos + radius * (qCos(angle2) * u_axis + qSin(angle2) * v_axis);
|
|
||||||
|
|
||||||
vertices << p1.x() << p1.y() << p1.z();
|
|
||||||
vertices << p2.x() << p2.y() << p2.z();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_viewport->shaderProgram()->setUniformValue(m_viewport->colorLoc(), QVector4D(1.0f, 1.0f, 0.0f, 1.0f));
|
|
||||||
m_viewport->vbo().bind();
|
|
||||||
m_viewport->vbo().allocate(vertices.constData(), vertices.size() * sizeof(GLfloat));
|
|
||||||
glDrawArrays(GL_LINES, 0, segments * 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircleTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection)
|
void CircleTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection)
|
||||||
{
|
{
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
if (m_isDefining) {
|
||||||
if (!m_isDefining || !currentPlaneOpt) return;
|
QVector3D worldPos;
|
||||||
const auto& plane = currentPlaneOpt.value();
|
QVector3D centerPos(m_centerPoint.X(), m_centerPoint.Y(), m_centerPoint.Z());
|
||||||
|
|
||||||
QVector3D worldPos;
|
QString diameterInput = m_viewport->property("diameterInput").toString();
|
||||||
QVector3D centerPos(m_centerPoint.X(), m_centerPoint.Y(), m_centerPoint.Z());
|
bool diameterFromInput = false;
|
||||||
|
double inputDiameter = 0;
|
||||||
|
|
||||||
QString diameterInput = m_viewport->property("diameterInput").toString();
|
if (!diameterInput.isEmpty()) {
|
||||||
bool diameterFromInput = false;
|
bool ok;
|
||||||
double inputDiameter = 0;
|
inputDiameter = diameterInput.toDouble(&ok);
|
||||||
|
if (ok) diameterFromInput = true;
|
||||||
if (!diameterInput.isEmpty()) {
|
|
||||||
bool ok;
|
|
||||||
inputDiameter = diameterInput.toDouble(&ok);
|
|
||||||
if (ok) diameterFromInput = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVector3D mousePos = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
|
||||||
QVector3D edgePos;
|
|
||||||
double diameter;
|
|
||||||
|
|
||||||
if (diameterFromInput) {
|
|
||||||
diameter = inputDiameter;
|
|
||||||
QVector3D mouseDir = mousePos - centerPos;
|
|
||||||
if (mouseDir.lengthSquared() < 1e-9) {
|
|
||||||
const auto& xDir = plane.XDirection();
|
|
||||||
mouseDir = QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
|
||||||
}
|
}
|
||||||
edgePos = centerPos + mouseDir.normalized() * (diameter / 2.0);
|
|
||||||
} else {
|
|
||||||
edgePos = mousePos;
|
|
||||||
if (m_viewport->isSnappingOrigin()) {
|
|
||||||
const auto& origin = plane.Location();
|
|
||||||
edgePos.setX(origin.X()); edgePos.setY(origin.Y()); edgePos.setZ(origin.Z());
|
|
||||||
} else if (m_viewport->isSnappingVertex()) {
|
|
||||||
edgePos.setX(m_viewport->snapVertex().X()); edgePos.setY(m_viewport->snapVertex().Y()); edgePos.setZ(m_viewport->snapVertex().Z());
|
|
||||||
}
|
|
||||||
diameter = (edgePos - centerPos).length() * 2.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
QVector3D mousePos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
QFontMetrics fm(painter.font());
|
QVector3D edgePos;
|
||||||
|
double diameter;
|
||||||
|
|
||||||
// Diameter dimension
|
if (diameterFromInput) {
|
||||||
QVector3D diameterTextPos3D = (centerPos + edgePos) / 2.0f;
|
diameter = inputDiameter;
|
||||||
QVector3D screenPosD = m_viewport->project(diameterTextPos3D, modelView, projection, m_viewport->rect());
|
QVector3D mouseDir = mousePos - centerPos;
|
||||||
if (screenPosD.z() < 1.0f) {
|
if (mouseDir.lengthSquared() < 1e-9) {
|
||||||
QString diameterText = diameterFromInput ? diameterInput : QString::number(diameter, 'f', 2);
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY || m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
QRect textRect = fm.boundingRect(diameterText + "__");
|
mouseDir = QVector3D(1, 0, 0);
|
||||||
textRect.moveCenter(screenPosD.toPoint());
|
} else { // YZ
|
||||||
if (m_viewport->property("dimensionEditMode").toString() == "diameter") {
|
mouseDir = QVector3D(0, 1, 0);
|
||||||
painter.fillRect(textRect.adjusted(-4, -2, 4, 2), QColor(64, 128, 255));
|
}
|
||||||
|
}
|
||||||
|
edgePos = centerPos + mouseDir.normalized() * (diameter / 2.0);
|
||||||
} else {
|
} else {
|
||||||
painter.fillRect(textRect.adjusted(-4, -2, 4, 2), QColor(50, 50, 50));
|
edgePos = mousePos;
|
||||||
|
if (m_viewport->isSnappingOrigin()) {
|
||||||
|
edgePos.setX(0); edgePos.setY(0); edgePos.setZ(0);
|
||||||
|
} else if (m_viewport->isSnappingVertex()) {
|
||||||
|
edgePos.setX(m_viewport->snapVertex().X()); edgePos.setY(m_viewport->snapVertex().Y()); edgePos.setZ(m_viewport->snapVertex().Z());
|
||||||
|
}
|
||||||
|
diameter = (edgePos - centerPos).length() * 2.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
QFontMetrics fm(painter.font());
|
||||||
|
|
||||||
|
// Diameter dimension
|
||||||
|
QVector3D diameterTextPos3D = (centerPos + edgePos) / 2.0f;
|
||||||
|
QVector3D screenPosD = m_viewport->project(diameterTextPos3D, modelView, projection, m_viewport->rect());
|
||||||
|
if (screenPosD.z() < 1.0f) {
|
||||||
|
QString diameterText = diameterFromInput ? diameterInput : QString::number(diameter, 'f', 2);
|
||||||
|
QRect textRect = fm.boundingRect(diameterText + "__");
|
||||||
|
textRect.moveCenter(screenPosD.toPoint());
|
||||||
|
if (m_viewport->property("dimensionEditMode").toString() == "diameter") {
|
||||||
|
painter.fillRect(textRect.adjusted(-4, -2, 4, 2), QColor(64, 128, 255));
|
||||||
|
} else {
|
||||||
|
painter.fillRect(textRect.adjusted(-4, -2, 4, 2), QColor(50, 50, 50));
|
||||||
|
}
|
||||||
|
painter.setPen(Qt::white);
|
||||||
|
painter.drawText(textRect, Qt::AlignCenter, diameterText);
|
||||||
}
|
}
|
||||||
painter.setPen(Qt::white);
|
|
||||||
painter.drawText(textRect, Qt::AlignCenter, diameterText);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef CIRCLETOOL_H
|
#ifndef CIRCLETOOL_H
|
||||||
#define CIRCLETOOL_H
|
#define CIRCLETOOL_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "DebugWindow.h"
|
|
||||||
#include "Camera.h"
|
|
||||||
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QTextEdit>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
DebugWindow::DebugWindow(QWidget *parent)
|
|
||||||
: QDialog(parent)
|
|
||||||
{
|
|
||||||
setWindowTitle("Debug Info");
|
|
||||||
resize(600, 400);
|
|
||||||
|
|
||||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
|
||||||
m_textEdit = new QTextEdit();
|
|
||||||
m_textEdit->setReadOnly(true);
|
|
||||||
m_textEdit->setText("Debug window is active.");
|
|
||||||
layout->addWidget(m_textEdit);
|
|
||||||
setLayout(layout);
|
|
||||||
}
|
|
||||||
|
|
||||||
DebugWindow::~DebugWindow()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void DebugWindow::updateCameraInfo(const Camera* camera)
|
|
||||||
{
|
|
||||||
if (!camera) {
|
|
||||||
m_textEdit->setText("Camera not available.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString info;
|
|
||||||
info += "Camera Info:\n";
|
|
||||||
info += "----------------\n";
|
|
||||||
info += QString("Rotation (X, Y): (%1, %2)\n").arg(camera->xRotation()).arg(camera->yRotation());
|
|
||||||
info += QString("Zoom: %1\n").arg(camera->zoom());
|
|
||||||
info += QString("Pan (X, Y): (%1, %2)\n").arg(camera->panX()).arg(camera->panY());
|
|
||||||
info += QString("UI Camera Distance: %1\n").arg(camera->uiCameraDistance());
|
|
||||||
info += "\n";
|
|
||||||
info += "Saved State:\n";
|
|
||||||
info += "----------------\n";
|
|
||||||
info += QString("Rotation (X, Y): (%1, %2)\n").arg(camera->savedXRot()).arg(camera->savedYRot());
|
|
||||||
info += QString("Zoom: %1\n").arg(camera->savedZoom());
|
|
||||||
info += QString("Pan (X, Y): (%1, %2)\n").arg(camera->savedPanX()).arg(camera->savedPanY());
|
|
||||||
|
|
||||||
m_textEdit->setText(info);
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef DEBUGWINDOW_H
|
|
||||||
#define DEBUGWINDOW_H
|
|
||||||
|
|
||||||
#include <QDialog>
|
|
||||||
|
|
||||||
class QTextEdit;
|
|
||||||
class Camera;
|
|
||||||
|
|
||||||
class DebugWindow : public QDialog
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit DebugWindow(QWidget *parent = nullptr);
|
|
||||||
~DebugWindow();
|
|
||||||
|
|
||||||
void updateCameraInfo(const Camera* camera);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QTextEdit* m_textEdit;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DEBUGWINDOW_H
|
|
||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "Document.h"
|
#include "Document.h"
|
||||||
#include "Feature.h"
|
#include "Feature.h"
|
||||||
#include "SketchFeature.h"
|
#include "SketchFeature.h"
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef DOCUMENT_H
|
#ifndef DOCUMENT_H
|
||||||
#define DOCUMENT_H
|
#define DOCUMENT_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "Feature.h"
|
#include "Feature.h"
|
||||||
|
|
||||||
Feature::Feature(const QString& name) : m_name(name)
|
Feature::Feature(const QString& name) : m_name(name)
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef FEATURE_H
|
#ifndef FEATURE_H
|
||||||
#define FEATURE_H
|
#define FEATURE_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "FeatureBrowser.h"
|
#include "FeatureBrowser.h"
|
||||||
#include "Document.h"
|
#include "Document.h"
|
||||||
#include "Feature.h"
|
#include "Feature.h"
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef FEATUREBROWSER_H
|
#ifndef FEATUREBROWSER_H
|
||||||
#define FEATUREBROWSER_H
|
#define FEATUREBROWSER_H
|
||||||
|
|
||||||
|
|||||||
+236
-248
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "LineTool.h"
|
#include "LineTool.h"
|
||||||
#include "ViewportWidget.h"
|
#include "ViewportWidget.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
@@ -13,13 +6,6 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <optional>
|
|
||||||
#include <gp_Ax2.hxx>
|
|
||||||
#include <gp_Pnt2d.hxx>
|
|
||||||
#include <gp_Dir2d.hxx>
|
|
||||||
#include <gp_Vec2d.hxx>
|
|
||||||
#include <gp_Vec.hxx>
|
|
||||||
#include <ElCLib.hxx>
|
|
||||||
|
|
||||||
LineTool::LineTool(ViewportWidget* viewport)
|
LineTool::LineTool(ViewportWidget* viewport)
|
||||||
: SketchTool(viewport)
|
: SketchTool(viewport)
|
||||||
@@ -41,10 +27,6 @@ void LineTool::activate()
|
|||||||
|
|
||||||
void LineTool::mousePressEvent(QMouseEvent *event)
|
void LineTool::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
|
||||||
if (!currentPlaneOpt) return;
|
|
||||||
const auto& plane = currentPlaneOpt.value();
|
|
||||||
|
|
||||||
gp_Pnt p;
|
gp_Pnt p;
|
||||||
QString dimInput = m_viewport->property("dimensionInput").toString();
|
QString dimInput = m_viewport->property("dimensionInput").toString();
|
||||||
QString angleInput = m_viewport->property("angleInput").toString();
|
QString angleInput = m_viewport->property("angleInput").toString();
|
||||||
@@ -75,23 +57,19 @@ void LineTool::mousePressEvent(QMouseEvent *event)
|
|||||||
if (m_viewport->property("isChainedLine").toBool()) {
|
if (m_viewport->property("isChainedLine").toBool()) {
|
||||||
refDir = m_viewport->property("previousLineDirection").value<QVector3D>();
|
refDir = m_viewport->property("previousLineDirection").value<QVector3D>();
|
||||||
} else {
|
} else {
|
||||||
const auto& xDir = plane.XDirection();
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY || m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) refDir = QVector3D(1, 0, 0);
|
||||||
refDir = QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
else refDir = QVector3D(0, 0, -1);
|
||||||
}
|
}
|
||||||
QVector3D currentMouseWorldPos = m_viewport->unproject(event->pos(), plane);
|
QVector3D currentMouseWorldPos = m_viewport->unproject(event->pos(), m_viewport->currentPlane());
|
||||||
QVector3D mouseVec = currentMouseWorldPos - startPos;
|
QVector3D mouseVec = currentMouseWorldPos - startPos;
|
||||||
|
double mouseAngle;
|
||||||
gp_Pnt startPnt(startPos.x(), startPos.y(), startPos.z());
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) mouseAngle = qRadiansToDegrees(atan2(mouseVec.z(), mouseVec.x()));
|
||||||
gp_Pnt mousePnt(currentMouseWorldPos.x(), currentMouseWorldPos.y(), currentMouseWorldPos.z());
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) mouseAngle = qRadiansToDegrees(atan2(mouseVec.y(), mouseVec.x()));
|
||||||
gp_Dir refDirGp(refDir.x(), refDir.y(), refDir.z());
|
else mouseAngle = qRadiansToDegrees(atan2(mouseVec.z(), mouseVec.y()));
|
||||||
|
double refAngle;
|
||||||
gp_Pnt2d startPnt2d(gp_Vec(plane.Location(), startPnt).Dot(plane.XDirection()), gp_Vec(plane.Location(), startPnt).Dot(plane.YDirection()));
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) refAngle = qRadiansToDegrees(atan2(refDir.z(), refDir.x()));
|
||||||
gp_Pnt2d mousePnt2d(gp_Vec(plane.Location(), mousePnt).Dot(plane.XDirection()), gp_Vec(plane.Location(), mousePnt).Dot(plane.YDirection()));
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) refAngle = qRadiansToDegrees(atan2(refDir.y(), refDir.x()));
|
||||||
gp_Dir2d refDir2d(refDirGp.Dot(plane.XDirection()), refDirGp.Dot(plane.YDirection()));
|
else refAngle = qRadiansToDegrees(atan2(refDir.z(), refDir.y()));
|
||||||
|
|
||||||
gp_Vec2d mouseVec2d(startPnt2d, mousePnt2d);
|
|
||||||
double mouseAngle = qRadiansToDegrees(atan2(mouseVec2d.Y(), mouseVec2d.X()));
|
|
||||||
double refAngle = qRadiansToDegrees(atan2(refDir2d.Y(), refDir2d.X()));
|
|
||||||
double relativeMouseAngle = mouseAngle - refAngle;
|
double relativeMouseAngle = mouseAngle - refAngle;
|
||||||
while (relativeMouseAngle <= -180.0) relativeMouseAngle += 360.0;
|
while (relativeMouseAngle <= -180.0) relativeMouseAngle += 360.0;
|
||||||
while (relativeMouseAngle > 180.0) relativeMouseAngle -= 360.0;
|
while (relativeMouseAngle > 180.0) relativeMouseAngle -= 360.0;
|
||||||
@@ -106,9 +84,10 @@ void LineTool::mousePressEvent(QMouseEvent *event)
|
|||||||
snappedAngle = -inputAngleDegrees;
|
snappedAngle = -inputAngleDegrees;
|
||||||
}
|
}
|
||||||
double finalAngleRad = qDegreesToRadians(refAngle + snappedAngle);
|
double finalAngleRad = qDegreesToRadians(refAngle + snappedAngle);
|
||||||
gp_Dir2d finalDir2d(cos(finalAngleRad), sin(finalAngleRad));
|
QVector3D finalDir;
|
||||||
gp_Dir finalDir3d = ElCLib::To3d(plane, finalDir2d);
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) finalDir = QVector3D(cos(finalAngleRad), 0, sin(finalAngleRad));
|
||||||
QVector3D finalDir(finalDir3d.X(), finalDir3d.Y(), finalDir3d.Z());
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) finalDir = QVector3D(cos(finalAngleRad), sin(finalAngleRad), 0);
|
||||||
|
else finalDir = QVector3D(0, cos(finalAngleRad), sin(finalAngleRad));
|
||||||
double lineLength;
|
double lineLength;
|
||||||
if (lengthFromInput) lineLength = inputLength;
|
if (lengthFromInput) lineLength = inputLength;
|
||||||
else {
|
else {
|
||||||
@@ -117,37 +96,34 @@ void LineTool::mousePressEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
worldPos = startPos + lineLength * finalDir;
|
worldPos = startPos + lineLength * finalDir;
|
||||||
} else if (lengthFromInput) {
|
} else if (lengthFromInput) {
|
||||||
QVector3D currentMouseWorldPos = m_viewport->unproject(event->pos(), plane);
|
QVector3D currentMouseWorldPos = m_viewport->unproject(event->pos(), m_viewport->currentPlane());
|
||||||
QVector3D dir = (currentMouseWorldPos - startPos);
|
QVector3D dir = (currentMouseWorldPos - startPos);
|
||||||
if (dir.length() > 1e-6) {
|
if (dir.length() > 1e-6) {
|
||||||
dir.normalize();
|
dir.normalize();
|
||||||
worldPos = startPos + inputLength * dir;
|
worldPos = startPos + inputLength * dir;
|
||||||
} else {
|
} else {
|
||||||
const auto& xDir = plane.XDirection();
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY || m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) worldPos = startPos + QVector3D(inputLength, 0, 0);
|
||||||
worldPos = startPos + inputLength * QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
else worldPos = startPos + QVector3D(0, inputLength, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.SetCoord(worldPos.x(), worldPos.y(), worldPos.z());
|
p.SetCoord(worldPos.x(), worldPos.y(), worldPos.z());
|
||||||
} else {
|
} else {
|
||||||
if (m_viewport->isSnappingOrigin()) {
|
if (m_viewport->isSnappingOrigin()) {
|
||||||
p = plane.Location();
|
p.SetCoord(0, 0, 0);
|
||||||
} else if (m_viewport->isSnappingVertex()) {
|
} else if (m_viewport->isSnappingVertex()) {
|
||||||
p = m_viewport->snapVertex();
|
p = m_viewport->snapVertex();
|
||||||
} else {
|
} else {
|
||||||
QVector3D worldPosQ = m_viewport->unproject(event->pos(), plane);
|
QVector3D worldPos = m_viewport->unproject(event->pos(), m_viewport->currentPlane());
|
||||||
gp_Pnt worldPos(worldPosQ.x(), worldPosQ.y(), worldPosQ.z());
|
if (m_viewport->isSnappingHorizontal()) {
|
||||||
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) worldPos.setZ(m_firstLinePoint.Z());
|
||||||
if (m_viewport->isSnappingHorizontal() || m_viewport->isSnappingVertical()) {
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) worldPos.setY(m_firstLinePoint.Y());
|
||||||
gp_Pnt2d worldPos2d(gp_Vec(plane.Location(), worldPos).Dot(plane.XDirection()), gp_Vec(plane.Location(), worldPos).Dot(plane.YDirection()));
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) worldPos.setZ(m_firstLinePoint.Z());
|
||||||
gp_Pnt2d firstPoint2d(gp_Vec(plane.Location(), m_firstLinePoint).Dot(plane.XDirection()), gp_Vec(plane.Location(), m_firstLinePoint).Dot(plane.YDirection()));
|
} else if (m_viewport->isSnappingVertical()) {
|
||||||
if (m_viewport->isSnappingHorizontal()) {
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) worldPos.setX(m_firstLinePoint.X());
|
||||||
worldPos2d.SetY(firstPoint2d.Y());
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) worldPos.setX(m_firstLinePoint.X());
|
||||||
} else { // vertical
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) worldPos.setY(m_firstLinePoint.Y());
|
||||||
worldPos2d.SetX(firstPoint2d.X());
|
|
||||||
}
|
|
||||||
worldPos = ElCLib::To3d(plane, worldPos2d);
|
|
||||||
}
|
}
|
||||||
p = worldPos;
|
p.SetCoord(worldPos.x(), worldPos.y(), worldPos.z());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,27 +150,27 @@ void LineTool::mousePressEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
void LineTool::mouseMoveEvent(QMouseEvent *event)
|
void LineTool::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
|
||||||
if (!m_isDefining || !currentPlaneOpt) return;
|
|
||||||
const auto& plane = currentPlaneOpt.value();
|
|
||||||
|
|
||||||
bool oldIsSnappingHorizontal = m_viewport->isSnappingHorizontal();
|
bool oldIsSnappingHorizontal = m_viewport->isSnappingHorizontal();
|
||||||
bool oldIsSnappingVertical = m_viewport->isSnappingVertical();
|
bool oldIsSnappingVertical = m_viewport->isSnappingVertical();
|
||||||
m_viewport->setSnappingHorizontal(false);
|
m_viewport->setSnappingHorizontal(false);
|
||||||
m_viewport->setSnappingVertical(false);
|
m_viewport->setSnappingVertical(false);
|
||||||
|
|
||||||
if (m_isDefining && !m_viewport->isSnappingOrigin() && !m_viewport->isSnappingVertex()) {
|
if (m_isDefining && !m_viewport->isSnappingOrigin() && !m_viewport->isSnappingVertex()) {
|
||||||
QVector3D worldPosQ = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
QVector3D worldPos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
gp_Pnt worldPos(worldPosQ.x(), worldPosQ.y(), worldPosQ.z());
|
QVector3D startPos(m_firstLinePoint.X(), m_firstLinePoint.Y(), m_firstLinePoint.Z());
|
||||||
gp_Pnt startPos = m_firstLinePoint;
|
QVector3D delta = worldPos - startPos;
|
||||||
|
|
||||||
gp_Pnt2d worldPos2d(gp_Vec(plane.Location(), worldPos).Dot(plane.XDirection()), gp_Vec(plane.Location(), worldPos).Dot(plane.YDirection()));
|
if (delta.length() > 1e-6) {
|
||||||
gp_Pnt2d startPos2d(gp_Vec(plane.Location(), startPos).Dot(plane.XDirection()), gp_Vec(plane.Location(), startPos).Dot(plane.YDirection()));
|
|
||||||
gp_Vec2d delta(startPos2d, worldPos2d);
|
|
||||||
|
|
||||||
if (delta.Magnitude() > 1e-6) {
|
|
||||||
const double snapAngleThreshold = qDegreesToRadians(2.0);
|
const double snapAngleThreshold = qDegreesToRadians(2.0);
|
||||||
double angle = atan2(delta.Y(), delta.X());
|
double angle = 0;
|
||||||
|
|
||||||
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
|
angle = atan2(delta.z(), delta.x());
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
|
angle = atan2(delta.y(), delta.x());
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) {
|
||||||
|
angle = atan2(delta.z(), delta.y());
|
||||||
|
}
|
||||||
|
|
||||||
if (qAbs(sin(angle)) < sin(snapAngleThreshold)) {
|
if (qAbs(sin(angle)) < sin(snapAngleThreshold)) {
|
||||||
m_viewport->setSnappingHorizontal(true);
|
m_viewport->setSnappingHorizontal(true);
|
||||||
@@ -211,10 +187,6 @@ void LineTool::mouseMoveEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
void LineTool::finalizeCreation()
|
void LineTool::finalizeCreation()
|
||||||
{
|
{
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
|
||||||
if (!currentPlaneOpt) return;
|
|
||||||
const auto& plane = currentPlaneOpt.value();
|
|
||||||
|
|
||||||
QVector3D worldPos;
|
QVector3D worldPos;
|
||||||
QVector3D startPos(m_firstLinePoint.X(), m_firstLinePoint.Y(), m_firstLinePoint.Z());
|
QVector3D startPos(m_firstLinePoint.X(), m_firstLinePoint.Y(), m_firstLinePoint.Z());
|
||||||
// This is duplicated from paintGL to ensure consistent line creation
|
// This is duplicated from paintGL to ensure consistent line creation
|
||||||
@@ -241,23 +213,19 @@ void LineTool::finalizeCreation()
|
|||||||
if (m_viewport->property("isChainedLine").toBool()) {
|
if (m_viewport->property("isChainedLine").toBool()) {
|
||||||
refDir = m_viewport->property("previousLineDirection").value<QVector3D>();
|
refDir = m_viewport->property("previousLineDirection").value<QVector3D>();
|
||||||
} else {
|
} else {
|
||||||
const auto& xDir = plane.XDirection();
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY || m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) refDir = QVector3D(1, 0, 0);
|
||||||
refDir = QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
else refDir = QVector3D(0, 0, -1);
|
||||||
}
|
}
|
||||||
QVector3D currentMouseWorldPos = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
QVector3D currentMouseWorldPos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
QVector3D mouseVec = currentMouseWorldPos - startPos;
|
QVector3D mouseVec = currentMouseWorldPos - startPos;
|
||||||
|
double mouseAngle;
|
||||||
gp_Pnt startPnt(startPos.x(), startPos.y(), startPos.z());
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) mouseAngle = qRadiansToDegrees(atan2(mouseVec.z(), mouseVec.x()));
|
||||||
gp_Pnt mousePnt(currentMouseWorldPos.x(), currentMouseWorldPos.y(), currentMouseWorldPos.z());
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) mouseAngle = qRadiansToDegrees(atan2(mouseVec.y(), mouseVec.x()));
|
||||||
gp_Dir refDirGp(refDir.x(), refDir.y(), refDir.z());
|
else mouseAngle = qRadiansToDegrees(atan2(mouseVec.z(), mouseVec.y()));
|
||||||
|
double refAngle;
|
||||||
gp_Pnt2d startPnt2d(gp_Vec(plane.Location(), startPnt).Dot(plane.XDirection()), gp_Vec(plane.Location(), startPnt).Dot(plane.YDirection()));
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) refAngle = qRadiansToDegrees(atan2(refDir.z(), refDir.x()));
|
||||||
gp_Pnt2d mousePnt2d(gp_Vec(plane.Location(), mousePnt).Dot(plane.XDirection()), gp_Vec(plane.Location(), mousePnt).Dot(plane.YDirection()));
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) refAngle = qRadiansToDegrees(atan2(refDir.y(), refDir.x()));
|
||||||
gp_Dir2d refDir2d(refDirGp.Dot(plane.XDirection()), refDirGp.Dot(plane.YDirection()));
|
else refAngle = qRadiansToDegrees(atan2(refDir.z(), refDir.y()));
|
||||||
|
|
||||||
gp_Vec2d mouseVec2d(startPnt2d, mousePnt2d);
|
|
||||||
double mouseAngle = qRadiansToDegrees(atan2(mouseVec2d.Y(), mouseVec2d.X()));
|
|
||||||
double refAngle = qRadiansToDegrees(atan2(refDir2d.Y(), refDir2d.X()));
|
|
||||||
double relativeMouseAngle = mouseAngle - refAngle;
|
double relativeMouseAngle = mouseAngle - refAngle;
|
||||||
while (relativeMouseAngle <= -180.0) relativeMouseAngle += 360.0;
|
while (relativeMouseAngle <= -180.0) relativeMouseAngle += 360.0;
|
||||||
while (relativeMouseAngle > 180.0) relativeMouseAngle -= 360.0;
|
while (relativeMouseAngle > 180.0) relativeMouseAngle -= 360.0;
|
||||||
@@ -272,9 +240,10 @@ void LineTool::finalizeCreation()
|
|||||||
snappedAngle = -inputAngleDegrees;
|
snappedAngle = -inputAngleDegrees;
|
||||||
}
|
}
|
||||||
double finalAngleRad = qDegreesToRadians(refAngle + snappedAngle);
|
double finalAngleRad = qDegreesToRadians(refAngle + snappedAngle);
|
||||||
gp_Dir2d finalDir2d(cos(finalAngleRad), sin(finalAngleRad));
|
QVector3D finalDir;
|
||||||
gp_Dir finalDir3d = ElCLib::To3d(plane, finalDir2d);
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) finalDir = QVector3D(cos(finalAngleRad), 0, sin(finalAngleRad));
|
||||||
QVector3D finalDir(finalDir3d.X(), finalDir3d.Y(), finalDir3d.Z());
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) finalDir = QVector3D(cos(finalAngleRad), sin(finalAngleRad), 0);
|
||||||
|
else finalDir = QVector3D(0, cos(finalAngleRad), sin(finalAngleRad));
|
||||||
double lineLength;
|
double lineLength;
|
||||||
if (lengthFromInput) lineLength = inputLength;
|
if (lengthFromInput) lineLength = inputLength;
|
||||||
else {
|
else {
|
||||||
@@ -283,17 +252,17 @@ void LineTool::finalizeCreation()
|
|||||||
}
|
}
|
||||||
worldPos = startPos + lineLength * finalDir;
|
worldPos = startPos + lineLength * finalDir;
|
||||||
} else if (lengthFromInput) {
|
} else if (lengthFromInput) {
|
||||||
QVector3D currentMouseWorldPos = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
QVector3D currentMouseWorldPos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
QVector3D dir = (currentMouseWorldPos - startPos);
|
QVector3D dir = (currentMouseWorldPos - startPos);
|
||||||
if (dir.length() > 1e-6) {
|
if (dir.length() > 1e-6) {
|
||||||
dir.normalize();
|
dir.normalize();
|
||||||
worldPos = startPos + inputLength * dir;
|
worldPos = startPos + inputLength * dir;
|
||||||
} else {
|
} else {
|
||||||
const auto& xDir = plane.XDirection();
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY || m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) worldPos = startPos + QVector3D(inputLength, 0, 0);
|
||||||
worldPos = startPos + inputLength * QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
else worldPos = startPos + QVector3D(0, inputLength, 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
worldPos = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
worldPos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
}
|
}
|
||||||
|
|
||||||
gp_Pnt p;
|
gp_Pnt p;
|
||||||
@@ -313,10 +282,6 @@ void LineTool::finalizeCreation()
|
|||||||
void LineTool::paintGL()
|
void LineTool::paintGL()
|
||||||
{
|
{
|
||||||
if (m_isDefining) {
|
if (m_isDefining) {
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
|
||||||
if (!currentPlaneOpt) return;
|
|
||||||
const auto& plane = currentPlaneOpt.value();
|
|
||||||
|
|
||||||
QVector<GLfloat> vertices;
|
QVector<GLfloat> vertices;
|
||||||
QVector3D worldPos;
|
QVector3D worldPos;
|
||||||
QVector3D startPos(m_firstLinePoint.X(), m_firstLinePoint.Y(), m_firstLinePoint.Z());
|
QVector3D startPos(m_firstLinePoint.X(), m_firstLinePoint.Y(), m_firstLinePoint.Z());
|
||||||
@@ -344,24 +309,26 @@ void LineTool::paintGL()
|
|||||||
if (m_viewport->property("isChainedLine").toBool()) {
|
if (m_viewport->property("isChainedLine").toBool()) {
|
||||||
refDir = m_viewport->property("previousLineDirection").value<QVector3D>();
|
refDir = m_viewport->property("previousLineDirection").value<QVector3D>();
|
||||||
} else {
|
} else {
|
||||||
const auto& xDir = plane.XDirection();
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY || m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
refDir = QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
refDir = QVector3D(1, 0, 0);
|
||||||
|
} else { // YZ
|
||||||
|
refDir = QVector3D(0, 0, -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector3D currentMouseWorldPos = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
QVector3D currentMouseWorldPos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
QVector3D mouseVec = currentMouseWorldPos - startPos;
|
QVector3D mouseVec = currentMouseWorldPos - startPos;
|
||||||
|
|
||||||
gp_Pnt startPnt(startPos.x(), startPos.y(), startPos.z());
|
// Quadrant snapping
|
||||||
gp_Pnt mousePnt(currentMouseWorldPos.x(), currentMouseWorldPos.y(), currentMouseWorldPos.z());
|
double mouseAngle;
|
||||||
gp_Dir refDirGp(refDir.x(), refDir.y(), refDir.z());
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) mouseAngle = qRadiansToDegrees(atan2(mouseVec.z(), mouseVec.x()));
|
||||||
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) mouseAngle = qRadiansToDegrees(atan2(mouseVec.y(), mouseVec.x()));
|
||||||
|
else mouseAngle = qRadiansToDegrees(atan2(mouseVec.z(), mouseVec.y()));
|
||||||
|
|
||||||
gp_Pnt2d startPnt2d(gp_Vec(plane.Location(), startPnt).Dot(plane.XDirection()), gp_Vec(plane.Location(), startPnt).Dot(plane.YDirection()));
|
double refAngle;
|
||||||
gp_Pnt2d mousePnt2d(gp_Vec(plane.Location(), mousePnt).Dot(plane.XDirection()), gp_Vec(plane.Location(), mousePnt).Dot(plane.YDirection()));
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) refAngle = qRadiansToDegrees(atan2(refDir.z(), refDir.x()));
|
||||||
gp_Dir2d refDir2d(refDirGp.Dot(plane.XDirection()), refDirGp.Dot(plane.YDirection()));
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) refAngle = qRadiansToDegrees(atan2(refDir.y(), refDir.x()));
|
||||||
|
else refAngle = qRadiansToDegrees(atan2(refDir.z(), refDir.y()));
|
||||||
gp_Vec2d mouseVec2d(startPnt2d, mousePnt2d);
|
|
||||||
double mouseAngle = qRadiansToDegrees(atan2(mouseVec2d.Y(), mouseVec2d.X()));
|
|
||||||
double refAngle = qRadiansToDegrees(atan2(refDir2d.Y(), refDir2d.X()));
|
|
||||||
|
|
||||||
double relativeMouseAngle = mouseAngle - refAngle;
|
double relativeMouseAngle = mouseAngle - refAngle;
|
||||||
while (relativeMouseAngle <= -180.0) relativeMouseAngle += 360.0;
|
while (relativeMouseAngle <= -180.0) relativeMouseAngle += 360.0;
|
||||||
@@ -379,9 +346,10 @@ void LineTool::paintGL()
|
|||||||
}
|
}
|
||||||
|
|
||||||
double finalAngleRad = qDegreesToRadians(refAngle + snappedAngle);
|
double finalAngleRad = qDegreesToRadians(refAngle + snappedAngle);
|
||||||
gp_Dir2d finalDir2d(cos(finalAngleRad), sin(finalAngleRad));
|
QVector3D finalDir;
|
||||||
gp_Dir finalDir3d = ElCLib::To3d(plane, finalDir2d);
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) finalDir = QVector3D(cos(finalAngleRad), 0, sin(finalAngleRad));
|
||||||
QVector3D finalDir(finalDir3d.X(), finalDir3d.Y(), finalDir3d.Z());
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) finalDir = QVector3D(cos(finalAngleRad), sin(finalAngleRad), 0);
|
||||||
|
else finalDir = QVector3D(0, cos(finalAngleRad), sin(finalAngleRad));
|
||||||
|
|
||||||
double lineLength;
|
double lineLength;
|
||||||
if (lengthFromInput) {
|
if (lengthFromInput) {
|
||||||
@@ -393,34 +361,33 @@ void LineTool::paintGL()
|
|||||||
worldPos = startPos + lineLength * finalDir;
|
worldPos = startPos + lineLength * finalDir;
|
||||||
|
|
||||||
} else if (lengthFromInput) {
|
} else if (lengthFromInput) {
|
||||||
QVector3D currentMouseWorldPos = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
QVector3D currentMouseWorldPos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
QVector3D dir = (currentMouseWorldPos - startPos);
|
QVector3D dir = (currentMouseWorldPos - startPos);
|
||||||
if (dir.length() > 1e-6) {
|
if (dir.length() > 1e-6) {
|
||||||
dir.normalize();
|
dir.normalize();
|
||||||
worldPos = startPos + inputLength * dir;
|
worldPos = startPos + inputLength * dir;
|
||||||
} else {
|
} else {
|
||||||
const auto& xDir = plane.XDirection();
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY || m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
worldPos = startPos + inputLength * QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
worldPos = startPos + QVector3D(inputLength, 0, 0);
|
||||||
|
} else {
|
||||||
|
worldPos = startPos + QVector3D(0, inputLength, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
worldPos = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
worldPos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
gp_Pnt worldPosPnt(worldPos.x(), worldPos.y(), worldPos.z());
|
|
||||||
|
|
||||||
if (m_viewport->isSnappingOrigin()) {
|
if (m_viewport->isSnappingOrigin()) {
|
||||||
worldPosPnt = plane.Location();
|
worldPos.setX(0); worldPos.setY(0); worldPos.setZ(0);
|
||||||
} else if (m_viewport->isSnappingVertex()) {
|
} else if (m_viewport->isSnappingVertex()) {
|
||||||
worldPosPnt = m_viewport->snapVertex();
|
worldPos.setX(m_viewport->snapVertex().X()); worldPos.setY(m_viewport->snapVertex().Y()); worldPos.setZ(m_viewport->snapVertex().Z());
|
||||||
} else if (m_viewport->isSnappingHorizontal() || m_viewport->isSnappingVertical()) {
|
} else if (m_viewport->isSnappingHorizontal()) {
|
||||||
gp_Pnt2d worldPos2d(gp_Vec(plane.Location(), worldPosPnt).Dot(plane.XDirection()), gp_Vec(plane.Location(), worldPosPnt).Dot(plane.YDirection()));
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) worldPos.setZ(m_firstLinePoint.Z());
|
||||||
gp_Pnt2d firstPoint2d(gp_Vec(plane.Location(), m_firstLinePoint).Dot(plane.XDirection()), gp_Vec(plane.Location(), m_firstLinePoint).Dot(plane.YDirection()));
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) worldPos.setY(m_firstLinePoint.Y());
|
||||||
if (m_viewport->isSnappingHorizontal()) {
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) worldPos.setZ(m_firstLinePoint.Z());
|
||||||
worldPos2d.SetY(firstPoint2d.Y());
|
} else if (m_viewport->isSnappingVertical()) {
|
||||||
} else { // vertical
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) worldPos.setX(m_firstLinePoint.X());
|
||||||
worldPos2d.SetX(firstPoint2d.X());
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) worldPos.setX(m_firstLinePoint.X());
|
||||||
}
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) worldPos.setY(m_firstLinePoint.Y());
|
||||||
worldPosPnt = ElCLib::To3d(plane, worldPos2d);
|
|
||||||
}
|
}
|
||||||
worldPos.setX(worldPosPnt.X()); worldPos.setY(worldPosPnt.Y()); worldPos.setZ(worldPosPnt.Z());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vertices << m_firstLinePoint.X() << m_firstLinePoint.Y() << m_firstLinePoint.Z();
|
vertices << m_firstLinePoint.X() << m_firstLinePoint.Y() << m_firstLinePoint.Z();
|
||||||
@@ -442,25 +409,23 @@ void LineTool::paintGL()
|
|||||||
if (m_viewport->property("isChainedLine").toBool()) {
|
if (m_viewport->property("isChainedLine").toBool()) {
|
||||||
refDir = m_viewport->property("previousLineDirection").value<QVector3D>();
|
refDir = m_viewport->property("previousLineDirection").value<QVector3D>();
|
||||||
} else {
|
} else {
|
||||||
const auto& xDir = plane.XDirection();
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY || m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) refDir = QVector3D(1, 0, 0);
|
||||||
refDir = QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
else refDir = QVector3D(0, 0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (angleFromInput) {
|
if (angleFromInput) {
|
||||||
QVector3D currentMouseWorldPos = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
QVector3D currentMouseWorldPos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
QVector3D mouseVec = currentMouseWorldPos - startPos;
|
QVector3D mouseVec = currentMouseWorldPos - startPos;
|
||||||
|
|
||||||
gp_Pnt startPnt(startPos.x(), startPos.y(), startPos.z());
|
double mouseAngle;
|
||||||
gp_Pnt mousePnt(currentMouseWorldPos.x(), currentMouseWorldPos.y(), currentMouseWorldPos.z());
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) mouseAngle = qRadiansToDegrees(atan2(mouseVec.z(), mouseVec.x()));
|
||||||
gp_Dir refDirGp(refDir.x(), refDir.y(), refDir.z());
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) mouseAngle = qRadiansToDegrees(atan2(mouseVec.y(), mouseVec.x()));
|
||||||
|
else mouseAngle = qRadiansToDegrees(atan2(mouseVec.z(), mouseVec.y()));
|
||||||
|
|
||||||
gp_Pnt2d startPnt2d(gp_Vec(plane.Location(), startPnt).Dot(plane.XDirection()), gp_Vec(plane.Location(), startPnt).Dot(plane.YDirection()));
|
double refAngleForQuadrant;
|
||||||
gp_Pnt2d mousePnt2d(gp_Vec(plane.Location(), mousePnt).Dot(plane.XDirection()), gp_Vec(plane.Location(), mousePnt).Dot(plane.YDirection()));
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) refAngleForQuadrant = qRadiansToDegrees(atan2(refDir.z(), refDir.x()));
|
||||||
gp_Dir2d refDir2d(refDirGp.Dot(plane.XDirection()), refDirGp.Dot(plane.YDirection()));
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) refAngleForQuadrant = qRadiansToDegrees(atan2(refDir.y(), refDir.x()));
|
||||||
|
else refAngleForQuadrant = qRadiansToDegrees(atan2(refDir.z(), refDir.y()));
|
||||||
gp_Vec2d mouseVec2d(startPnt2d, mousePnt2d);
|
|
||||||
double mouseAngle = qRadiansToDegrees(atan2(mouseVec2d.Y(), mouseVec2d.X()));
|
|
||||||
double refAngleForQuadrant = qRadiansToDegrees(atan2(refDir2d.Y(), refDir2d.X()));
|
|
||||||
|
|
||||||
double relativeMouseAngle = mouseAngle - refAngleForQuadrant;
|
double relativeMouseAngle = mouseAngle - refAngleForQuadrant;
|
||||||
while (relativeMouseAngle <= -180.0) relativeMouseAngle += 360.0;
|
while (relativeMouseAngle <= -180.0) relativeMouseAngle += 360.0;
|
||||||
@@ -475,14 +440,16 @@ void LineTool::paintGL()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gp_Dir refDirGp(refDir.x(), refDir.y(), refDir.z());
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
gp_Dir lineDirGp(lineVec.x(), lineVec.y(), lineVec.z());
|
refAngle = atan2(refDir.z(), refDir.x());
|
||||||
|
lineAngle = atan2(lineVec.z(), lineVec.x());
|
||||||
gp_Dir2d refDir2d(refDirGp.Dot(plane.XDirection()), refDirGp.Dot(plane.YDirection()));
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
gp_Dir2d lineDir2d(lineDirGp.Dot(plane.XDirection()), lineDirGp.Dot(plane.YDirection()));
|
refAngle = atan2(refDir.y(), refDir.x());
|
||||||
|
lineAngle = atan2(lineVec.y(), lineVec.x());
|
||||||
refAngle = atan2(refDir2d.Y(), refDir2d.X());
|
} else { // YZ
|
||||||
lineAngle = atan2(lineDir2d.Y(), lineDir2d.X());
|
refAngle = atan2(refDir.z(), refDir.y());
|
||||||
|
lineAngle = atan2(lineVec.z(), lineVec.y());
|
||||||
|
}
|
||||||
|
|
||||||
angleDiff = lineAngle - refAngle;
|
angleDiff = lineAngle - refAngle;
|
||||||
while (angleDiff <= -M_PI) angleDiff += 2 * M_PI;
|
while (angleDiff <= -M_PI) angleDiff += 2 * M_PI;
|
||||||
@@ -492,11 +459,14 @@ void LineTool::paintGL()
|
|||||||
|
|
||||||
vertices.clear();
|
vertices.clear();
|
||||||
|
|
||||||
gp_Dir lineDirGp(lineVec.x(), lineVec.y(), lineVec.z());
|
QVector3D perpVec;
|
||||||
gp_Dir2d lineDir2d(lineDirGp.Dot(plane.XDirection()), lineDirGp.Dot(plane.YDirection()));
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
gp_Dir2d perpDir2d(-lineDir2d.Y(), lineDir2d.X());
|
perpVec = QVector3D(-lineVec.z(), 0, lineVec.x()).normalized();
|
||||||
gp_Dir perpDir3d = ElCLib::To3d(plane, perpDir2d);
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
QVector3D perpVec(perpDir3d.X(), perpDir3d.Y(), perpDir3d.Z());
|
perpVec = QVector3D(-lineVec.y(), lineVec.x(), 0).normalized();
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) {
|
||||||
|
perpVec = QVector3D(0, -lineVec.z(), lineVec.y()).normalized();
|
||||||
|
}
|
||||||
|
|
||||||
if (angleDiff < 0) {
|
if (angleDiff < 0) {
|
||||||
perpVec = -perpVec;
|
perpVec = -perpVec;
|
||||||
@@ -543,11 +513,9 @@ void LineTool::paintGL()
|
|||||||
for (int i = 0; i <= numSegments; ++i) {
|
for (int i = 0; i <= numSegments; ++i) {
|
||||||
double angle = refAngle + (lineAngle - refAngle) * i / numSegments;
|
double angle = refAngle + (lineAngle - refAngle) * i / numSegments;
|
||||||
QVector3D p;
|
QVector3D p;
|
||||||
const auto& xDir = plane.XDirection();
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) p = startPos + radius * QVector3D(cos(angle), 0, sin(angle));
|
||||||
const auto& yDir = plane.YDirection();
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) p = startPos + radius * QVector3D(cos(angle), sin(angle), 0);
|
||||||
QVector3D u_axis(xDir.X(), xDir.Y(), xDir.Z());
|
else p = startPos + radius * QVector3D(0, cos(angle), sin(angle));
|
||||||
QVector3D v_axis(yDir.X(), yDir.Y(), yDir.Z());
|
|
||||||
p = startPos + radius * (cos(angle) * u_axis + sin(angle) * v_axis);
|
|
||||||
vertices << p.x() << p.y() << p.z();
|
vertices << p.x() << p.y() << p.z();
|
||||||
}
|
}
|
||||||
glLineWidth(1.0f);
|
glLineWidth(1.0f);
|
||||||
@@ -565,13 +533,17 @@ void LineTool::paintGL()
|
|||||||
// End arrowhead
|
// End arrowhead
|
||||||
QVector3D endPoint(vertices[vertices.size()-3], vertices[vertices.size()-2], vertices[vertices.size()-1]);
|
QVector3D endPoint(vertices[vertices.size()-3], vertices[vertices.size()-2], vertices[vertices.size()-1]);
|
||||||
double endAngle = lineAngle;
|
double endAngle = lineAngle;
|
||||||
const auto& xDir = plane.XDirection();
|
|
||||||
const auto& yDir = plane.YDirection();
|
|
||||||
QVector3D u_axis(xDir.X(), xDir.Y(), xDir.Z());
|
|
||||||
QVector3D v_axis(yDir.X(), yDir.Y(), yDir.Z());
|
|
||||||
QVector3D radialDir_end, tangentDir_end;
|
QVector3D radialDir_end, tangentDir_end;
|
||||||
radialDir_end = cos(endAngle) * u_axis + sin(endAngle) * v_axis;
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
tangentDir_end = -sin(endAngle) * u_axis + cos(endAngle) * v_axis;
|
radialDir_end = QVector3D(cos(endAngle), 0, sin(endAngle));
|
||||||
|
tangentDir_end = QVector3D(-sin(endAngle), 0, cos(endAngle));
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
|
radialDir_end = QVector3D(cos(endAngle), sin(endAngle), 0);
|
||||||
|
tangentDir_end = QVector3D(-sin(endAngle), cos(endAngle), 0);
|
||||||
|
} else {
|
||||||
|
radialDir_end = QVector3D(0, cos(endAngle), sin(endAngle));
|
||||||
|
tangentDir_end = QVector3D(0, -sin(endAngle), cos(endAngle));
|
||||||
|
}
|
||||||
QVector3D arc_arrow_base_end = endPoint - sign * arcArrowLength * tangentDir_end;
|
QVector3D arc_arrow_base_end = endPoint - sign * arcArrowLength * tangentDir_end;
|
||||||
QVector3D arc_arrowP1_end = arc_arrow_base_end + arcArrowWidth * radialDir_end;
|
QVector3D arc_arrowP1_end = arc_arrow_base_end + arcArrowWidth * radialDir_end;
|
||||||
QVector3D arc_arrowP2_end = arc_arrow_base_end - arcArrowWidth * radialDir_end;
|
QVector3D arc_arrowP2_end = arc_arrow_base_end - arcArrowWidth * radialDir_end;
|
||||||
@@ -582,8 +554,16 @@ void LineTool::paintGL()
|
|||||||
QVector3D startPoint(vertices[0], vertices[1], vertices[2]);
|
QVector3D startPoint(vertices[0], vertices[1], vertices[2]);
|
||||||
double startAngle = refAngle;
|
double startAngle = refAngle;
|
||||||
QVector3D radialDir_start, tangentDir_start;
|
QVector3D radialDir_start, tangentDir_start;
|
||||||
radialDir_start = cos(startAngle) * u_axis + sin(startAngle) * v_axis;
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
tangentDir_start = -sin(startAngle) * u_axis + cos(startAngle) * v_axis;
|
radialDir_start = QVector3D(cos(startAngle), 0, sin(startAngle));
|
||||||
|
tangentDir_start = QVector3D(-sin(startAngle), 0, cos(startAngle));
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
|
radialDir_start = QVector3D(cos(startAngle), sin(startAngle), 0);
|
||||||
|
tangentDir_start = QVector3D(-sin(startAngle), cos(startAngle), 0);
|
||||||
|
} else {
|
||||||
|
radialDir_start = QVector3D(0, cos(startAngle), sin(startAngle));
|
||||||
|
tangentDir_start = QVector3D(0, -sin(startAngle), cos(startAngle));
|
||||||
|
}
|
||||||
QVector3D arc_arrow_base_start = startPoint + sign * arcArrowLength * tangentDir_start;
|
QVector3D arc_arrow_base_start = startPoint + sign * arcArrowLength * tangentDir_start;
|
||||||
QVector3D arc_arrowP1_start = arc_arrow_base_start + arcArrowWidth * radialDir_start;
|
QVector3D arc_arrowP1_start = arc_arrow_base_start + arcArrowWidth * radialDir_start;
|
||||||
QVector3D arc_arrowP2_start = arc_arrow_base_start - arcArrowWidth * radialDir_start;
|
QVector3D arc_arrowP2_start = arc_arrow_base_start - arcArrowWidth * radialDir_start;
|
||||||
@@ -602,21 +582,29 @@ void LineTool::paintGL()
|
|||||||
QVector3D midPoint = (startPos + worldPos) / 2.0;
|
QVector3D midPoint = (startPos + worldPos) / 2.0;
|
||||||
const float indicatorSize = 0.02f * -m_viewport->camera()->zoom();
|
const float indicatorSize = 0.02f * -m_viewport->camera()->zoom();
|
||||||
const float indicatorOffset = 0.02f * -m_viewport->camera()->zoom();
|
const float indicatorOffset = 0.02f * -m_viewport->camera()->zoom();
|
||||||
const auto& xDir = plane.XDirection();
|
|
||||||
const auto& yDir = plane.YDirection();
|
|
||||||
QVector3D u_axis(xDir.X(), xDir.Y(), xDir.Z());
|
|
||||||
QVector3D v_axis(yDir.X(), yDir.Y(), yDir.Z());
|
|
||||||
|
|
||||||
QVector3D p1, p2;
|
|
||||||
if (m_viewport->isSnappingHorizontal()) {
|
if (m_viewport->isSnappingHorizontal()) {
|
||||||
p1 = midPoint - indicatorSize * v_axis + indicatorOffset * u_axis;
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
p2 = midPoint + indicatorSize * v_axis + indicatorOffset * u_axis;
|
vertices << midPoint.x() - indicatorSize << midPoint.y() << midPoint.z() + indicatorOffset;
|
||||||
|
vertices << midPoint.x() + indicatorSize << midPoint.y() << midPoint.z() + indicatorOffset;
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
|
vertices << midPoint.x() - indicatorSize << midPoint.y() + indicatorOffset << midPoint.z();
|
||||||
|
vertices << midPoint.x() + indicatorSize << midPoint.y() + indicatorOffset << midPoint.z();
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) {
|
||||||
|
vertices << midPoint.x() << midPoint.y() - indicatorSize << midPoint.z() + indicatorOffset;
|
||||||
|
vertices << midPoint.x() << midPoint.y() + indicatorSize << midPoint.z() + indicatorOffset;
|
||||||
|
}
|
||||||
} else { // m_isSnappingVertical
|
} else { // m_isSnappingVertical
|
||||||
p1 = midPoint - indicatorSize * u_axis + indicatorOffset * v_axis;
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
p2 = midPoint + indicatorSize * u_axis + indicatorOffset * v_axis;
|
vertices << midPoint.x() + indicatorOffset << midPoint.y() << midPoint.z() - indicatorSize;
|
||||||
|
vertices << midPoint.x() + indicatorOffset << midPoint.y() << midPoint.z() + indicatorSize;
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
|
vertices << midPoint.x() + indicatorOffset << midPoint.y() - indicatorSize << midPoint.z();
|
||||||
|
vertices << midPoint.x() + indicatorOffset << midPoint.y() + indicatorSize << midPoint.z();
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) {
|
||||||
|
vertices << midPoint.x() << midPoint.y() + indicatorOffset << midPoint.z() - indicatorSize;
|
||||||
|
vertices << midPoint.x() << midPoint.y() + indicatorOffset << midPoint.z() + indicatorSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
vertices << p1.x() << p1.y() << p1.z();
|
|
||||||
vertices << p2.x() << p2.y() << p2.z();
|
|
||||||
m_viewport->vbo().bind();
|
m_viewport->vbo().bind();
|
||||||
m_viewport->vbo().allocate(vertices.constData(), vertices.size() * sizeof(GLfloat));
|
m_viewport->vbo().allocate(vertices.constData(), vertices.size() * sizeof(GLfloat));
|
||||||
glDrawArrays(GL_LINES, 0, 2);
|
glDrawArrays(GL_LINES, 0, 2);
|
||||||
@@ -627,10 +615,6 @@ void LineTool::paintGL()
|
|||||||
void LineTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection)
|
void LineTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection)
|
||||||
{
|
{
|
||||||
if (m_isDefining) {
|
if (m_isDefining) {
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
|
||||||
if (!currentPlaneOpt) return;
|
|
||||||
const auto& plane = currentPlaneOpt.value();
|
|
||||||
|
|
||||||
QVector3D worldPos;
|
QVector3D worldPos;
|
||||||
QVector3D startPos(m_firstLinePoint.X(), m_firstLinePoint.Y(), m_firstLinePoint.Z());
|
QVector3D startPos(m_firstLinePoint.X(), m_firstLinePoint.Y(), m_firstLinePoint.Z());
|
||||||
QString dimText;
|
QString dimText;
|
||||||
@@ -660,24 +644,25 @@ void LineTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMa
|
|||||||
if (m_viewport->property("isChainedLine").toBool()) {
|
if (m_viewport->property("isChainedLine").toBool()) {
|
||||||
refDir = m_viewport->property("previousLineDirection").value<QVector3D>();
|
refDir = m_viewport->property("previousLineDirection").value<QVector3D>();
|
||||||
} else {
|
} else {
|
||||||
const auto& xDir = plane.XDirection();
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY || m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
refDir = QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
refDir = QVector3D(1, 0, 0);
|
||||||
|
} else { // YZ
|
||||||
|
refDir = QVector3D(0, 0, -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector3D currentMouseWorldPos = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
QVector3D currentMouseWorldPos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
QVector3D mouseVec = currentMouseWorldPos - startPos;
|
QVector3D mouseVec = currentMouseWorldPos - startPos;
|
||||||
|
|
||||||
gp_Pnt startPnt(startPos.x(), startPos.y(), startPos.z());
|
double mouseAngle;
|
||||||
gp_Pnt mousePnt(currentMouseWorldPos.x(), currentMouseWorldPos.y(), currentMouseWorldPos.z());
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) mouseAngle = qRadiansToDegrees(atan2(mouseVec.z(), mouseVec.x()));
|
||||||
gp_Dir refDirGp(refDir.x(), refDir.y(), refDir.z());
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) mouseAngle = qRadiansToDegrees(atan2(mouseVec.y(), mouseVec.x()));
|
||||||
|
else mouseAngle = qRadiansToDegrees(atan2(mouseVec.z(), mouseVec.y()));
|
||||||
|
|
||||||
gp_Pnt2d startPnt2d(gp_Vec(plane.Location(), startPnt).Dot(plane.XDirection()), gp_Vec(plane.Location(), startPnt).Dot(plane.YDirection()));
|
double refAngle;
|
||||||
gp_Pnt2d mousePnt2d(gp_Vec(plane.Location(), mousePnt).Dot(plane.XDirection()), gp_Vec(plane.Location(), mousePnt).Dot(plane.YDirection()));
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) refAngle = qRadiansToDegrees(atan2(refDir.z(), refDir.x()));
|
||||||
gp_Dir2d refDir2d(refDirGp.Dot(plane.XDirection()), refDirGp.Dot(plane.YDirection()));
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) refAngle = qRadiansToDegrees(atan2(refDir.y(), refDir.x()));
|
||||||
|
else refAngle = qRadiansToDegrees(atan2(refDir.z(), refDir.y()));
|
||||||
gp_Vec2d mouseVec2d(startPnt2d, mousePnt2d);
|
|
||||||
double mouseAngle = qRadiansToDegrees(atan2(mouseVec2d.Y(), mouseVec2d.X()));
|
|
||||||
double refAngle = qRadiansToDegrees(atan2(refDir2d.Y(), refDir2d.X()));
|
|
||||||
|
|
||||||
double relativeMouseAngle = mouseAngle - refAngle;
|
double relativeMouseAngle = mouseAngle - refAngle;
|
||||||
while (relativeMouseAngle <= -180.0) relativeMouseAngle += 360.0;
|
while (relativeMouseAngle <= -180.0) relativeMouseAngle += 360.0;
|
||||||
@@ -695,9 +680,10 @@ void LineTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMa
|
|||||||
}
|
}
|
||||||
|
|
||||||
double finalAngleRad = qDegreesToRadians(refAngle + snappedAngle);
|
double finalAngleRad = qDegreesToRadians(refAngle + snappedAngle);
|
||||||
gp_Dir2d finalDir2d(cos(finalAngleRad), sin(finalAngleRad));
|
QVector3D finalDir;
|
||||||
gp_Dir finalDir3d = ElCLib::To3d(plane, finalDir2d);
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) finalDir = QVector3D(cos(finalAngleRad), 0, sin(finalAngleRad));
|
||||||
QVector3D finalDir(finalDir3d.X(), finalDir3d.Y(), finalDir3d.Z());
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) finalDir = QVector3D(cos(finalAngleRad), sin(finalAngleRad), 0);
|
||||||
|
else finalDir = QVector3D(0, cos(finalAngleRad), sin(finalAngleRad));
|
||||||
|
|
||||||
if (lengthFromInput) {
|
if (lengthFromInput) {
|
||||||
lineLength = inputLength;
|
lineLength = inputLength;
|
||||||
@@ -709,34 +695,33 @@ void LineTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMa
|
|||||||
|
|
||||||
} else if (lengthFromInput) {
|
} else if (lengthFromInput) {
|
||||||
lineLength = inputLength;
|
lineLength = inputLength;
|
||||||
QVector3D currentMouseWorldPos = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
QVector3D currentMouseWorldPos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
QVector3D dir = (currentMouseWorldPos - startPos);
|
QVector3D dir = (currentMouseWorldPos - startPos);
|
||||||
if (dir.length() > 1e-6) {
|
if (dir.length() > 1e-6) {
|
||||||
dir.normalize();
|
dir.normalize();
|
||||||
worldPos = startPos + inputLength * dir;
|
worldPos = startPos + inputLength * dir;
|
||||||
} else {
|
} else {
|
||||||
const auto& xDir = plane.XDirection();
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY || m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
worldPos = startPos + inputLength * QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
worldPos = startPos + QVector3D(inputLength, 0, 0);
|
||||||
|
} else {
|
||||||
|
worldPos = startPos + QVector3D(0, inputLength, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
worldPos = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
worldPos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
gp_Pnt worldPosPnt(worldPos.x(), worldPos.y(), worldPos.z());
|
|
||||||
|
|
||||||
if (m_viewport->isSnappingOrigin()) {
|
if (m_viewport->isSnappingOrigin()) {
|
||||||
worldPosPnt = plane.Location();
|
worldPos.setX(0); worldPos.setY(0); worldPos.setZ(0);
|
||||||
} else if (m_viewport->isSnappingVertex()) {
|
} else if (m_viewport->isSnappingVertex()) {
|
||||||
worldPosPnt = m_viewport->snapVertex();
|
worldPos.setX(m_viewport->snapVertex().X()); worldPos.setY(m_viewport->snapVertex().Y()); worldPos.setZ(m_viewport->snapVertex().Z());
|
||||||
} else if (m_viewport->isSnappingHorizontal() || m_viewport->isSnappingVertical()) {
|
} else if (m_viewport->isSnappingHorizontal()) {
|
||||||
gp_Pnt2d worldPos2d(gp_Vec(plane.Location(), worldPosPnt).Dot(plane.XDirection()), gp_Vec(plane.Location(), worldPosPnt).Dot(plane.YDirection()));
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) worldPos.setZ(m_firstLinePoint.Z());
|
||||||
gp_Pnt2d firstPoint2d(gp_Vec(plane.Location(), m_firstLinePoint).Dot(plane.XDirection()), gp_Vec(plane.Location(), m_firstLinePoint).Dot(plane.YDirection()));
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) worldPos.setY(m_firstLinePoint.Y());
|
||||||
if (m_viewport->isSnappingHorizontal()) {
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) worldPos.setZ(m_firstLinePoint.Z());
|
||||||
worldPos2d.SetY(firstPoint2d.Y());
|
} else if (m_viewport->isSnappingVertical()) {
|
||||||
} else { // vertical
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) worldPos.setX(m_firstLinePoint.X());
|
||||||
worldPos2d.SetX(firstPoint2d.X());
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) worldPos.setX(m_firstLinePoint.X());
|
||||||
}
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) worldPos.setY(m_firstLinePoint.Y());
|
||||||
worldPosPnt = ElCLib::To3d(plane, worldPos2d);
|
|
||||||
}
|
}
|
||||||
worldPos.setX(worldPosPnt.X()); worldPos.setY(worldPosPnt.Y()); worldPos.setZ(worldPosPnt.Z());
|
|
||||||
lineLength = (worldPos - startPos).length();
|
lineLength = (worldPos - startPos).length();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -747,26 +732,24 @@ void LineTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMa
|
|||||||
if (m_viewport->property("isChainedLine").toBool()) {
|
if (m_viewport->property("isChainedLine").toBool()) {
|
||||||
refDir = m_viewport->property("previousLineDirection").value<QVector3D>();
|
refDir = m_viewport->property("previousLineDirection").value<QVector3D>();
|
||||||
} else {
|
} else {
|
||||||
const auto& xDir = plane.XDirection();
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY || m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) refDir = QVector3D(1, 0, 0);
|
||||||
refDir = QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
else refDir = QVector3D(0, 0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector3D currentMouseWorldPosForText = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
QVector3D currentMouseWorldPosForText = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
QVector3D mouseVecForText = currentMouseWorldPosForText - startPos;
|
QVector3D mouseVecForText = currentMouseWorldPosForText - startPos;
|
||||||
|
|
||||||
if (angleFromInput) {
|
if (angleFromInput) {
|
||||||
if (mouseVecForText.length() > 1e-6) {
|
if (mouseVecForText.length() > 1e-6) {
|
||||||
gp_Pnt startPnt(startPos.x(), startPos.y(), startPos.z());
|
double mouseAngle;
|
||||||
gp_Pnt mousePnt(currentMouseWorldPosForText.x(), currentMouseWorldPosForText.y(), currentMouseWorldPosForText.z());
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) mouseAngle = qRadiansToDegrees(atan2(mouseVecForText.z(), mouseVecForText.x()));
|
||||||
gp_Dir refDirGp(refDir.x(), refDir.y(), refDir.z());
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) mouseAngle = qRadiansToDegrees(atan2(mouseVecForText.y(), mouseVecForText.x()));
|
||||||
|
else mouseAngle = qRadiansToDegrees(atan2(mouseVecForText.z(), mouseVecForText.y()));
|
||||||
|
|
||||||
gp_Pnt2d startPnt2d(gp_Vec(plane.Location(), startPnt).Dot(plane.XDirection()), gp_Vec(plane.Location(), startPnt).Dot(plane.YDirection()));
|
double refAngleForQuadrant;
|
||||||
gp_Pnt2d mousePnt2d(gp_Vec(plane.Location(), mousePnt).Dot(plane.XDirection()), gp_Vec(plane.Location(), mousePnt).Dot(plane.YDirection()));
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) refAngleForQuadrant = qRadiansToDegrees(atan2(refDir.z(), refDir.x()));
|
||||||
gp_Dir2d refDir2d(refDirGp.Dot(plane.XDirection()), refDirGp.Dot(plane.YDirection()));
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) refAngleForQuadrant = qRadiansToDegrees(atan2(refDir.y(), refDir.x()));
|
||||||
|
else refAngleForQuadrant = qRadiansToDegrees(atan2(refDir.z(), refDir.y()));
|
||||||
gp_Vec2d mouseVec2d(startPnt2d, mousePnt2d);
|
|
||||||
double mouseAngle = qRadiansToDegrees(atan2(mouseVec2d.Y(), mouseVec2d.X()));
|
|
||||||
double refAngleForQuadrant = qRadiansToDegrees(atan2(refDir2d.Y(), refDir2d.X()));
|
|
||||||
|
|
||||||
double relativeMouseAngle = mouseAngle - refAngleForQuadrant;
|
double relativeMouseAngle = mouseAngle - refAngleForQuadrant;
|
||||||
while (relativeMouseAngle <= -180.0) relativeMouseAngle += 360.0;
|
while (relativeMouseAngle <= -180.0) relativeMouseAngle += 360.0;
|
||||||
@@ -782,23 +765,30 @@ void LineTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gp_Dir refDirGp(refDir.x(), refDir.y(), refDir.z());
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
gp_Dir lineDirGp(lineVec.x(), lineVec.y(), lineVec.z());
|
refAngle = atan2(refDir.z(), refDir.x());
|
||||||
|
lineAngle = atan2(lineVec.z(), lineVec.x());
|
||||||
gp_Dir2d refDir2d(refDirGp.Dot(plane.XDirection()), refDirGp.Dot(plane.YDirection()));
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
gp_Dir2d lineDir2d(lineDirGp.Dot(plane.XDirection()), lineDirGp.Dot(plane.YDirection()));
|
refAngle = atan2(refDir.y(), refDir.x());
|
||||||
|
lineAngle = atan2(lineVec.y(), lineVec.x());
|
||||||
refAngle = atan2(refDir2d.Y(), refDir2d.X());
|
} else { // YZ
|
||||||
lineAngle = atan2(lineDir2d.Y(), lineDir2d.X());
|
refAngle = atan2(refDir.z(), refDir.y());
|
||||||
|
lineAngle = atan2(lineVec.z(), lineVec.y());
|
||||||
|
}
|
||||||
|
|
||||||
double angleDiff = lineAngle - refAngle;
|
double angleDiff = lineAngle - refAngle;
|
||||||
while (angleDiff <= -M_PI) angleDiff += 2 * M_PI;
|
while (angleDiff <= -M_PI) angleDiff += 2 * M_PI;
|
||||||
while (angleDiff > M_PI) angleDiff -= 2 * M_PI;
|
while (angleDiff > M_PI) angleDiff -= 2 * M_PI;
|
||||||
lineAngle = refAngle + angleDiff;
|
lineAngle = refAngle + angleDiff;
|
||||||
|
|
||||||
gp_Dir2d perpDir2d(-lineDir2d.Y(), lineDir2d.X());
|
QVector3D perpVec;
|
||||||
gp_Dir perpDir3d = ElCLib::To3d(plane, perpDir2d);
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
QVector3D perpVec(perpDir3d.X(), perpDir3d.Y(), perpDir3d.Z());
|
perpVec = QVector3D(-lineVec.z(), 0, lineVec.x()).normalized();
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
|
perpVec = QVector3D(-lineVec.y(), lineVec.x(), 0).normalized();
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) {
|
||||||
|
perpVec = QVector3D(0, -lineVec.z(), lineVec.y()).normalized();
|
||||||
|
}
|
||||||
|
|
||||||
if (angleDiff < 0) {
|
if (angleDiff < 0) {
|
||||||
perpVec = -perpVec;
|
perpVec = -perpVec;
|
||||||
@@ -841,11 +831,9 @@ void LineTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMa
|
|||||||
QVector3D textPos3DAngle;
|
QVector3D textPos3DAngle;
|
||||||
float textOffset = 0.035f * -m_viewport->camera()->zoom();
|
float textOffset = 0.035f * -m_viewport->camera()->zoom();
|
||||||
|
|
||||||
const auto& xDir = plane.XDirection();
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) textPos3DAngle = startPos + (radius + textOffset) * QVector3D(cos(midAngle), 0, sin(midAngle));
|
||||||
const auto& yDir = plane.YDirection();
|
else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) textPos3DAngle = startPos + (radius + textOffset) * QVector3D(cos(midAngle), sin(midAngle), 0);
|
||||||
QVector3D u_axis(xDir.X(), xDir.Y(), xDir.Z());
|
else textPos3DAngle = startPos + (radius + textOffset) * QVector3D(0, cos(midAngle), sin(midAngle));
|
||||||
QVector3D v_axis(yDir.X(), yDir.Y(), yDir.Z());
|
|
||||||
textPos3DAngle = startPos + (radius + textOffset) * (cos(midAngle) * u_axis + sin(midAngle) * v_axis);
|
|
||||||
|
|
||||||
QVector3D screenPosAngle = m_viewport->project(textPos3DAngle, modelView, projection, m_viewport->rect());
|
QVector3D screenPosAngle = m_viewport->project(textPos3DAngle, modelView, projection, m_viewport->rect());
|
||||||
if (screenPosAngle.z() < 1.0f) {
|
if (screenPosAngle.z() < 1.0f) {
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef LINETOOL_H
|
#ifndef LINETOOL_H
|
||||||
#define LINETOOL_H
|
#define LINETOOL_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,9 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "ViewportWidget.h"
|
#include "ViewportWidget.h"
|
||||||
#include "Document.h"
|
#include "Document.h"
|
||||||
#include "SketchFeature.h"
|
#include "SketchFeature.h"
|
||||||
#include "Feature.h"
|
#include "Feature.h"
|
||||||
#include "ApplicationController.h"
|
#include "ApplicationController.h"
|
||||||
#include "DebugWindow.h"
|
|
||||||
#include "Camera.h"
|
|
||||||
|
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
@@ -28,7 +19,6 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QProcessEnvironment>
|
|
||||||
|
|
||||||
MainWindow::MainWindow(ApplicationController* appController, QWidget *parent)
|
MainWindow::MainWindow(ApplicationController* appController, QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
@@ -51,10 +41,6 @@ MainWindow::MainWindow(ApplicationController* appController, QWidget *parent)
|
|||||||
QAction *saveAsAction = fileMenu->addAction("Save &As...");
|
QAction *saveAsAction = fileMenu->addAction("Save &As...");
|
||||||
connect(saveAsAction, &QAction::triggered, this, &MainWindow::saveAs);
|
connect(saveAsAction, &QAction::triggered, this, &MainWindow::saveAs);
|
||||||
|
|
||||||
QMenu *helpMenu = menuBar()->addMenu("&Help");
|
|
||||||
QAction *debugAction = helpMenu->addAction("&Debug");
|
|
||||||
connect(debugAction, &QAction::triggered, this, &MainWindow::showDebugWindow);
|
|
||||||
|
|
||||||
|
|
||||||
QToolBar* mainToolBar = addToolBar("Main Toolbar");
|
QToolBar* mainToolBar = addToolBar("Main Toolbar");
|
||||||
mainToolBar->setMovable(false);
|
mainToolBar->setMovable(false);
|
||||||
@@ -165,13 +151,6 @@ MainWindow::MainWindow(ApplicationController* appController, QWidget *parent)
|
|||||||
connect(m_viewport, &ViewportWidget::planeSelected, m_appController, &ApplicationController::onPlaneSelected);
|
connect(m_viewport, &ViewportWidget::planeSelected, m_appController, &ApplicationController::onPlaneSelected);
|
||||||
connect(m_viewport, &ViewportWidget::toolDeactivated, m_appController, [this]() { m_appController->setActiveTool(ApplicationController::ToolType::None); });
|
connect(m_viewport, &ViewportWidget::toolDeactivated, m_appController, [this]() { m_appController->setActiveTool(ApplicationController::ToolType::None); });
|
||||||
|
|
||||||
connect(m_viewport->camera(), &Camera::cameraChanged, this, &MainWindow::updateDebugInfo);
|
|
||||||
|
|
||||||
m_debugWindow = new DebugWindow(this);
|
|
||||||
if (QProcessEnvironment::systemEnvironment().value("DEBUG") == "true") {
|
|
||||||
showDebugWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateWindowTitle(QString());
|
updateWindowTitle(QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,17 +184,6 @@ bool MainWindow::saveAs()
|
|||||||
return m_appController->saveDocumentAs();
|
return m_appController->saveDocumentAs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showDebugWindow()
|
|
||||||
{
|
|
||||||
updateDebugInfo();
|
|
||||||
m_debugWindow->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::updateDebugInfo()
|
|
||||||
{
|
|
||||||
m_debugWindow->updateCameraInfo(m_viewport->camera());
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::enterSketchMode()
|
void MainWindow::enterSketchMode()
|
||||||
{
|
{
|
||||||
m_tabWidget->removeTab(m_tabWidget->indexOf(m_toolsTab));
|
m_tabWidget->removeTab(m_tabWidget->indexOf(m_toolsTab));
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef MAINWINDOW_H
|
#ifndef MAINWINDOW_H
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
@@ -17,7 +10,6 @@ class Feature;
|
|||||||
class QTabWidget;
|
class QTabWidget;
|
||||||
class QWidget;
|
class QWidget;
|
||||||
class ApplicationController;
|
class ApplicationController;
|
||||||
class DebugWindow;
|
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
@@ -34,9 +26,6 @@ private slots:
|
|||||||
void createSketch();
|
void createSketch();
|
||||||
void saveSketch();
|
void saveSketch();
|
||||||
|
|
||||||
void showDebugWindow();
|
|
||||||
void updateDebugInfo();
|
|
||||||
|
|
||||||
void enterSketchMode();
|
void enterSketchMode();
|
||||||
void exitSketchMode();
|
void exitSketchMode();
|
||||||
void updateWindowTitle(const QString& filePath);
|
void updateWindowTitle(const QString& filePath);
|
||||||
@@ -47,7 +36,6 @@ protected:
|
|||||||
private:
|
private:
|
||||||
ApplicationController* m_appController;
|
ApplicationController* m_appController;
|
||||||
ViewportWidget *m_viewport;
|
ViewportWidget *m_viewport;
|
||||||
DebugWindow* m_debugWindow;
|
|
||||||
|
|
||||||
QTabWidget *m_tabWidget;
|
QTabWidget *m_tabWidget;
|
||||||
QWidget *m_solidTab;
|
QWidget *m_solidTab;
|
||||||
|
|||||||
+260
-231
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "RectangleTool.h"
|
#include "RectangleTool.h"
|
||||||
#include "ViewportWidget.h"
|
#include "ViewportWidget.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
@@ -15,11 +8,6 @@
|
|||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <optional>
|
|
||||||
#include <gp_Ax2.hxx>
|
|
||||||
#include <gp_Pnt2d.hxx>
|
|
||||||
#include <gp_Vec.hxx>
|
|
||||||
#include <ElCLib.hxx>
|
|
||||||
|
|
||||||
RectangleTool::RectangleTool(ViewportWidget* viewport)
|
RectangleTool::RectangleTool(ViewportWidget* viewport)
|
||||||
: SketchTool(viewport)
|
: SketchTool(viewport)
|
||||||
@@ -40,18 +28,14 @@ void RectangleTool::activate()
|
|||||||
|
|
||||||
void RectangleTool::mousePressEvent(QMouseEvent *event)
|
void RectangleTool::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
|
||||||
if (!currentPlaneOpt) return;
|
|
||||||
const auto& plane = currentPlaneOpt.value();
|
|
||||||
|
|
||||||
gp_Pnt p;
|
gp_Pnt p;
|
||||||
if (!m_isDefining) {
|
if (!m_isDefining) {
|
||||||
if (m_viewport->isSnappingOrigin()) {
|
if (m_viewport->isSnappingOrigin()) {
|
||||||
p = plane.Location();
|
p.SetCoord(0, 0, 0);
|
||||||
} else if (m_viewport->isSnappingVertex()) {
|
} else if (m_viewport->isSnappingVertex()) {
|
||||||
p = m_viewport->snapVertex();
|
p = m_viewport->snapVertex();
|
||||||
} else {
|
} else {
|
||||||
QVector3D worldPos = m_viewport->unproject(event->pos(), plane);
|
QVector3D worldPos = m_viewport->unproject(event->pos(), m_viewport->currentPlane());
|
||||||
p.SetCoord(worldPos.x(), worldPos.y(), worldPos.z());
|
p.SetCoord(worldPos.x(), worldPos.y(), worldPos.z());
|
||||||
}
|
}
|
||||||
m_firstRectanglePoint = p;
|
m_firstRectanglePoint = p;
|
||||||
@@ -60,8 +44,8 @@ void RectangleTool::mousePressEvent(QMouseEvent *event)
|
|||||||
m_viewport->setProperty("heightInput", "");
|
m_viewport->setProperty("heightInput", "");
|
||||||
m_viewport->setProperty("dimensionEditMode", "height");
|
m_viewport->setProperty("dimensionEditMode", "height");
|
||||||
} else {
|
} else {
|
||||||
QVector3D worldPosQ;
|
QVector3D worldPos;
|
||||||
gp_Pnt startPos = m_firstRectanglePoint;
|
QVector3D startPos(m_firstRectanglePoint.X(), m_firstRectanglePoint.Y(), m_firstRectanglePoint.Z());
|
||||||
|
|
||||||
QString widthInput = m_viewport->property("widthInput").toString();
|
QString widthInput = m_viewport->property("widthInput").toString();
|
||||||
QString heightInput = m_viewport->property("heightInput").toString();
|
QString heightInput = m_viewport->property("heightInput").toString();
|
||||||
@@ -80,35 +64,45 @@ void RectangleTool::mousePressEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (widthFromInput || heightFromInput) {
|
if (widthFromInput || heightFromInput) {
|
||||||
QVector3D mousePosQ = m_viewport->unproject(event->pos(), plane);
|
QVector3D mousePos = m_viewport->unproject(event->pos(), m_viewport->currentPlane());
|
||||||
gp_Pnt mousePos(mousePosQ.x(), mousePosQ.y(), mousePosQ.z());
|
QVector3D mouseDir = mousePos - startPos;
|
||||||
|
double current_w, current_h;
|
||||||
gp_Pnt2d startPos2d(gp_Vec(plane.Location(), startPos).Dot(plane.XDirection()), gp_Vec(plane.Location(), startPos).Dot(plane.YDirection()));
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
gp_Pnt2d mousePos2d(gp_Vec(plane.Location(), mousePos).Dot(plane.XDirection()), gp_Vec(plane.Location(), mousePos).Dot(plane.YDirection()));
|
current_w = qAbs(mouseDir.x());
|
||||||
|
current_h = qAbs(mouseDir.z());
|
||||||
double current_w = qAbs(mousePos2d.X() - startPos2d.X());
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
double current_h = qAbs(mousePos2d.Y() - startPos2d.Y());
|
current_w = qAbs(mouseDir.x());
|
||||||
|
current_h = qAbs(mouseDir.y());
|
||||||
|
} else { // YZ
|
||||||
|
current_w = qAbs(mouseDir.y());
|
||||||
|
current_h = qAbs(mouseDir.z());
|
||||||
|
}
|
||||||
double rect_w = widthFromInput ? inputWidth : current_w;
|
double rect_w = widthFromInput ? inputWidth : current_w;
|
||||||
double rect_h = heightFromInput ? inputHeight : current_h;
|
double rect_h = heightFromInput ? inputHeight : current_h;
|
||||||
|
int signX = (mouseDir.x() >= 0) ? 1 : -1;
|
||||||
int signX = (mousePos2d.X() >= startPos2d.X()) ? 1 : -1;
|
int signY = (mouseDir.y() >= 0) ? 1 : -1;
|
||||||
int signY = (mousePos2d.Y() >= startPos2d.Y()) ? 1 : -1;
|
int signZ = (mouseDir.z() >= 0) ? 1 : -1;
|
||||||
|
worldPos = startPos;
|
||||||
gp_Pnt2d endPos2d(startPos2d.X() + signX * rect_w, startPos2d.Y() + signY * rect_h);
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
gp_Pnt endPos3d = ElCLib::To3d(plane, endPos2d);
|
worldPos.setX(startPos.x() + signX * rect_w);
|
||||||
worldPosQ = QVector3D(endPos3d.X(), endPos3d.Y(), endPos3d.Z());
|
worldPos.setZ(startPos.z() + signZ * rect_h);
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
|
worldPos.setX(startPos.x() + signX * rect_w);
|
||||||
|
worldPos.setY(startPos.y() + signY * rect_h);
|
||||||
|
} else { // YZ
|
||||||
|
worldPos.setY(startPos.y() + signY * rect_w);
|
||||||
|
worldPos.setZ(startPos.z() + signZ * rect_h);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (m_viewport->isSnappingOrigin()) {
|
if (m_viewport->isSnappingOrigin()) {
|
||||||
const auto& origin = plane.Location();
|
worldPos.setX(0); worldPos.setY(0); worldPos.setZ(0);
|
||||||
worldPosQ.setX(origin.X()); worldPosQ.setY(origin.Y()); worldPosQ.setZ(origin.Z());
|
|
||||||
} else if (m_viewport->isSnappingVertex()) {
|
} else if (m_viewport->isSnappingVertex()) {
|
||||||
worldPosQ = QVector3D(m_viewport->snapVertex().X(), m_viewport->snapVertex().Y(), m_viewport->snapVertex().Z());
|
worldPos = QVector3D(m_viewport->snapVertex().X(), m_viewport->snapVertex().Y(), m_viewport->snapVertex().Z());
|
||||||
} else {
|
} else {
|
||||||
worldPosQ = m_viewport->unproject(event->pos(), plane);
|
worldPos = m_viewport->unproject(event->pos(), m_viewport->currentPlane());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.SetCoord(worldPosQ.x(), worldPosQ.y(), worldPosQ.z());
|
p.SetCoord(worldPos.x(), worldPos.y(), worldPos.z());
|
||||||
emit m_viewport->rectangleAdded(m_firstRectanglePoint, p);
|
emit m_viewport->rectangleAdded(m_firstRectanglePoint, p);
|
||||||
deactivate();
|
deactivate();
|
||||||
}
|
}
|
||||||
@@ -121,12 +115,8 @@ void RectangleTool::mouseMoveEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
void RectangleTool::finalizeCreation()
|
void RectangleTool::finalizeCreation()
|
||||||
{
|
{
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
QVector3D worldPos;
|
||||||
if (!currentPlaneOpt) return;
|
QVector3D startPos(m_firstRectanglePoint.X(), m_firstRectanglePoint.Y(), m_firstRectanglePoint.Z());
|
||||||
const auto& plane = currentPlaneOpt.value();
|
|
||||||
|
|
||||||
QVector3D worldPosQ;
|
|
||||||
gp_Pnt startPos = m_firstRectanglePoint;
|
|
||||||
|
|
||||||
QString widthInput = m_viewport->property("widthInput").toString();
|
QString widthInput = m_viewport->property("widthInput").toString();
|
||||||
QString heightInput = m_viewport->property("heightInput").toString();
|
QString heightInput = m_viewport->property("heightInput").toString();
|
||||||
@@ -145,30 +135,41 @@ void RectangleTool::finalizeCreation()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (widthFromInput || heightFromInput) {
|
if (widthFromInput || heightFromInput) {
|
||||||
QVector3D mousePosQ = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
QVector3D mousePos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
gp_Pnt mousePos(mousePosQ.x(), mousePosQ.y(), mousePosQ.z());
|
QVector3D mouseDir = mousePos - startPos;
|
||||||
|
double current_w, current_h;
|
||||||
gp_Pnt2d startPos2d(gp_Vec(plane.Location(), startPos).Dot(plane.XDirection()), gp_Vec(plane.Location(), startPos).Dot(plane.YDirection()));
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
gp_Pnt2d mousePos2d(gp_Vec(plane.Location(), mousePos).Dot(plane.XDirection()), gp_Vec(plane.Location(), mousePos).Dot(plane.YDirection()));
|
current_w = qAbs(mouseDir.x());
|
||||||
|
current_h = qAbs(mouseDir.z());
|
||||||
double current_w = qAbs(mousePos2d.X() - startPos2d.X());
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
double current_h = qAbs(mousePos2d.Y() - startPos2d.Y());
|
current_w = qAbs(mouseDir.x());
|
||||||
|
current_h = qAbs(mouseDir.y());
|
||||||
|
} else { // YZ
|
||||||
|
current_w = qAbs(mouseDir.y());
|
||||||
|
current_h = qAbs(mouseDir.z());
|
||||||
|
}
|
||||||
double rect_w = widthFromInput ? inputWidth : current_w;
|
double rect_w = widthFromInput ? inputWidth : current_w;
|
||||||
double rect_h = heightFromInput ? inputHeight : current_h;
|
double rect_h = heightFromInput ? inputHeight : current_h;
|
||||||
|
int signX = (mouseDir.x() >= 0) ? 1 : -1;
|
||||||
int signX = (mousePos2d.X() >= startPos2d.X()) ? 1 : -1;
|
int signY = (mouseDir.y() >= 0) ? 1 : -1;
|
||||||
int signY = (mousePos2d.Y() >= startPos2d.Y()) ? 1 : -1;
|
int signZ = (mouseDir.z() >= 0) ? 1 : -1;
|
||||||
|
worldPos = startPos;
|
||||||
gp_Pnt2d endPos2d(startPos2d.X() + signX * rect_w, startPos2d.Y() + signY * rect_h);
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
gp_Pnt endPos3d = ElCLib::To3d(plane, endPos2d);
|
worldPos.setX(startPos.x() + signX * rect_w);
|
||||||
worldPosQ = QVector3D(endPos3d.X(), endPos3d.Y(), endPos3d.Z());
|
worldPos.setZ(startPos.z() + signZ * rect_h);
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
|
worldPos.setX(startPos.x() + signX * rect_w);
|
||||||
|
worldPos.setY(startPos.y() + signY * rect_h);
|
||||||
|
} else { // YZ
|
||||||
|
worldPos.setY(startPos.y() + signY * rect_w);
|
||||||
|
worldPos.setZ(startPos.z() + signZ * rect_h);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
worldPosQ = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
worldPos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
}
|
}
|
||||||
|
|
||||||
gp_Pnt p;
|
gp_Pnt p;
|
||||||
p.SetCoord(worldPosQ.x(), worldPosQ.y(), worldPosQ.z());
|
p.SetCoord(worldPos.x(), worldPos.y(), worldPos.z());
|
||||||
|
|
||||||
emit m_viewport->rectangleAdded(m_firstRectanglePoint, p);
|
emit m_viewport->rectangleAdded(m_firstRectanglePoint, p);
|
||||||
deactivate();
|
deactivate();
|
||||||
@@ -176,188 +177,216 @@ void RectangleTool::finalizeCreation()
|
|||||||
|
|
||||||
void RectangleTool::paintGL()
|
void RectangleTool::paintGL()
|
||||||
{
|
{
|
||||||
if (!m_isDefining) return;
|
if (m_isDefining) {
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
QVector<GLfloat> vertices;
|
||||||
if (!currentPlaneOpt) return;
|
QVector3D worldPos;
|
||||||
const auto& plane = currentPlaneOpt.value();
|
QVector3D startPos(m_firstRectanglePoint.X(), m_firstRectanglePoint.Y(), m_firstRectanglePoint.Z());
|
||||||
|
|
||||||
QVector<GLfloat> vertices;
|
QString widthInput = m_viewport->property("widthInput").toString();
|
||||||
QVector3D worldPosQ;
|
QString heightInput = m_viewport->property("heightInput").toString();
|
||||||
gp_Pnt startPos = m_firstRectanglePoint;
|
bool widthFromInput = false;
|
||||||
|
bool heightFromInput = false;
|
||||||
|
double inputWidth = 0, inputHeight = 0;
|
||||||
|
|
||||||
QString widthInput = m_viewport->property("widthInput").toString();
|
if (!widthInput.isEmpty()) {
|
||||||
QString heightInput = m_viewport->property("heightInput").toString();
|
bool ok;
|
||||||
bool widthFromInput = false;
|
inputWidth = widthInput.toDouble(&ok);
|
||||||
bool heightFromInput = false;
|
if (ok) widthFromInput = true;
|
||||||
double inputWidth = 0, inputHeight = 0;
|
|
||||||
|
|
||||||
if (!widthInput.isEmpty()) {
|
|
||||||
bool ok;
|
|
||||||
inputWidth = widthInput.toDouble(&ok);
|
|
||||||
if (ok) widthFromInput = true;
|
|
||||||
}
|
|
||||||
if (!heightInput.isEmpty()) {
|
|
||||||
bool ok;
|
|
||||||
inputHeight = heightInput.toDouble(&ok);
|
|
||||||
if (ok) heightFromInput = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVector3D mousePosQ = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
|
||||||
gp_Pnt mousePos(mousePosQ.x(), mousePosQ.y(), mousePosQ.z());
|
|
||||||
|
|
||||||
if (widthFromInput || heightFromInput) {
|
|
||||||
gp_Pnt2d startPos2d(gp_Vec(plane.Location(), startPos).Dot(plane.XDirection()), gp_Vec(plane.Location(), startPos).Dot(plane.YDirection()));
|
|
||||||
gp_Pnt2d mousePos2d(gp_Vec(plane.Location(), mousePos).Dot(plane.XDirection()), gp_Vec(plane.Location(), mousePos).Dot(plane.YDirection()));
|
|
||||||
|
|
||||||
double current_w = qAbs(mousePos2d.X() - startPos2d.X());
|
|
||||||
double current_h = qAbs(mousePos2d.Y() - startPos2d.Y());
|
|
||||||
|
|
||||||
double rect_w = widthFromInput ? inputWidth : current_w;
|
|
||||||
double rect_h = heightFromInput ? inputHeight : current_h;
|
|
||||||
|
|
||||||
int signX = (mousePos2d.X() >= startPos2d.X()) ? 1 : -1;
|
|
||||||
int signY = (mousePos2d.Y() >= startPos2d.Y()) ? 1 : -1;
|
|
||||||
|
|
||||||
gp_Pnt2d endPos2d(startPos2d.X() + signX * rect_w, startPos2d.Y() + signY * rect_h);
|
|
||||||
gp_Pnt endPos3d = ElCLib::To3d(plane, endPos2d);
|
|
||||||
worldPosQ = QVector3D(endPos3d.X(), endPos3d.Y(), endPos3d.Z());
|
|
||||||
} else {
|
|
||||||
worldPosQ = mousePosQ;
|
|
||||||
if (m_viewport->isSnappingOrigin()) {
|
|
||||||
const auto& origin = plane.Location();
|
|
||||||
worldPosQ.setX(origin.X()); worldPosQ.setY(origin.Y()); worldPosQ.setZ(origin.Z());
|
|
||||||
} else if (m_viewport->isSnappingVertex()) {
|
|
||||||
worldPosQ.setX(m_viewport->snapVertex().X()); worldPosQ.setY(m_viewport->snapVertex().Y()); worldPosQ.setZ(m_viewport->snapVertex().Z());
|
|
||||||
}
|
}
|
||||||
|
if (!heightInput.isEmpty()) {
|
||||||
|
bool ok;
|
||||||
|
inputHeight = heightInput.toDouble(&ok);
|
||||||
|
if (ok) heightFromInput = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector3D mousePos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
|
|
||||||
|
if (widthFromInput || heightFromInput) {
|
||||||
|
QVector3D mouseDir = mousePos - startPos;
|
||||||
|
double current_w, current_h;
|
||||||
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
|
current_w = qAbs(mouseDir.x());
|
||||||
|
current_h = qAbs(mouseDir.z());
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
|
current_w = qAbs(mouseDir.x());
|
||||||
|
current_h = qAbs(mouseDir.y());
|
||||||
|
} else { // YZ
|
||||||
|
current_w = qAbs(mouseDir.y());
|
||||||
|
current_h = qAbs(mouseDir.z());
|
||||||
|
}
|
||||||
|
double rect_w = widthFromInput ? inputWidth : current_w;
|
||||||
|
double rect_h = heightFromInput ? inputHeight : current_h;
|
||||||
|
int signX = (mouseDir.x() >= 0) ? 1 : -1;
|
||||||
|
int signY = (mouseDir.y() >= 0) ? 1 : -1;
|
||||||
|
int signZ = (mouseDir.z() >= 0) ? 1 : -1;
|
||||||
|
worldPos = startPos;
|
||||||
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
|
worldPos.setX(startPos.x() + signX * rect_w);
|
||||||
|
worldPos.setZ(startPos.z() + signZ * rect_h);
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
|
worldPos.setX(startPos.x() + signX * rect_w);
|
||||||
|
worldPos.setY(startPos.y() + signY * rect_h);
|
||||||
|
} else { // YZ
|
||||||
|
worldPos.setY(startPos.y() + signY * rect_w);
|
||||||
|
worldPos.setZ(startPos.z() + signZ * rect_h);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
worldPos = mousePos;
|
||||||
|
if (m_viewport->isSnappingOrigin()) {
|
||||||
|
worldPos.setX(0); worldPos.setY(0); worldPos.setZ(0);
|
||||||
|
} else if (m_viewport->isSnappingVertex()) {
|
||||||
|
worldPos.setX(m_viewport->snapVertex().X()); worldPos.setY(m_viewport->snapVertex().Y()); worldPos.setZ(m_viewport->snapVertex().Z());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector3D p1 = startPos;
|
||||||
|
QVector3D p2, p3, p4;
|
||||||
|
p3 = worldPos;
|
||||||
|
|
||||||
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
|
p2.setX(p3.x()); p2.setY(p1.y()); p2.setZ(p1.z());
|
||||||
|
p4.setX(p1.x()); p4.setY(p1.y()); p4.setZ(p3.z());
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
|
p2.setX(p3.x()); p2.setY(p1.y()); p2.setZ(p1.z());
|
||||||
|
p4.setX(p1.x()); p4.setY(p3.y()); p4.setZ(p1.z());
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) {
|
||||||
|
p2.setX(p1.x()); p2.setY(p3.y()); p2.setZ(p1.z());
|
||||||
|
p4.setX(p1.x()); p4.setY(p1.y()); p4.setZ(p3.z());
|
||||||
|
}
|
||||||
|
|
||||||
|
vertices << p1.x() << p1.y() << p1.z();
|
||||||
|
vertices << p2.x() << p2.y() << p2.z();
|
||||||
|
vertices << p2.x() << p2.y() << p2.z();
|
||||||
|
vertices << p3.x() << p3.y() << p3.z();
|
||||||
|
vertices << p3.x() << p3.y() << p3.z();
|
||||||
|
vertices << p4.x() << p4.y() << p4.z();
|
||||||
|
vertices << p4.x() << p4.y() << p4.z();
|
||||||
|
vertices << p1.x() << p1.y() << p1.z();
|
||||||
|
|
||||||
|
m_viewport->shaderProgram()->setUniformValue(m_viewport->colorLoc(), QVector4D(1.0f, 1.0f, 0.0f, 1.0f));
|
||||||
|
m_viewport->vbo().bind();
|
||||||
|
m_viewport->vbo().allocate(vertices.constData(), vertices.size() * sizeof(GLfloat));
|
||||||
|
glDrawArrays(GL_LINES, 0, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
gp_Pnt p1_3d = startPos;
|
|
||||||
gp_Pnt p3_3d(worldPosQ.x(), worldPosQ.y(), worldPosQ.z());
|
|
||||||
gp_Pnt2d p1_2d(gp_Vec(plane.Location(), p1_3d).Dot(plane.XDirection()), gp_Vec(plane.Location(), p1_3d).Dot(plane.YDirection()));
|
|
||||||
gp_Pnt2d p3_2d(gp_Vec(plane.Location(), p3_3d).Dot(plane.XDirection()), gp_Vec(plane.Location(), p3_3d).Dot(plane.YDirection()));
|
|
||||||
|
|
||||||
gp_Pnt2d p2_2d(p3_2d.X(), p1_2d.Y());
|
|
||||||
gp_Pnt2d p4_2d(p1_2d.X(), p3_2d.Y());
|
|
||||||
|
|
||||||
gp_Pnt p2_3d = ElCLib::To3d(plane, p2_2d);
|
|
||||||
gp_Pnt p4_3d = ElCLib::To3d(plane, p4_2d);
|
|
||||||
|
|
||||||
vertices << p1_3d.X() << p1_3d.Y() << p1_3d.Z();
|
|
||||||
vertices << p2_3d.X() << p2_3d.Y() << p2_3d.Z();
|
|
||||||
vertices << p2_3d.X() << p2_3d.Y() << p2_3d.Z();
|
|
||||||
vertices << p3_3d.X() << p3_3d.Y() << p3_3d.Z();
|
|
||||||
vertices << p3_3d.X() << p3_3d.Y() << p3_3d.Z();
|
|
||||||
vertices << p4_3d.X() << p4_3d.Y() << p4_3d.Z();
|
|
||||||
vertices << p4_3d.X() << p4_3d.Y() << p4_3d.Z();
|
|
||||||
vertices << p1_3d.X() << p1_3d.Y() << p1_3d.Z();
|
|
||||||
|
|
||||||
m_viewport->shaderProgram()->setUniformValue(m_viewport->colorLoc(), QVector4D(1.0f, 1.0f, 0.0f, 1.0f));
|
|
||||||
m_viewport->vbo().bind();
|
|
||||||
m_viewport->vbo().allocate(vertices.constData(), vertices.size() * sizeof(GLfloat));
|
|
||||||
glDrawArrays(GL_LINES, 0, 8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RectangleTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection)
|
void RectangleTool::paint2D(QPainter& painter, const QMatrix4x4& modelView, const QMatrix4x4& projection)
|
||||||
{
|
{
|
||||||
if (!m_isDefining) return;
|
if (m_isDefining) {
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
QVector3D worldPos;
|
||||||
if (!currentPlaneOpt) return;
|
QVector3D p1_3d(m_firstRectanglePoint.X(), m_firstRectanglePoint.Y(), m_firstRectanglePoint.Z());
|
||||||
const auto& plane = currentPlaneOpt.value();
|
|
||||||
|
|
||||||
QVector3D worldPosQ;
|
QString widthInput = m_viewport->property("widthInput").toString();
|
||||||
gp_Pnt p1_3d = m_firstRectanglePoint;
|
QString heightInput = m_viewport->property("heightInput").toString();
|
||||||
|
bool widthFromInput = false;
|
||||||
|
bool heightFromInput = false;
|
||||||
|
double inputWidth = 0, inputHeight = 0;
|
||||||
|
|
||||||
QString widthInput = m_viewport->property("widthInput").toString();
|
if (!widthInput.isEmpty()) {
|
||||||
QString heightInput = m_viewport->property("heightInput").toString();
|
bool ok;
|
||||||
bool widthFromInput = false;
|
inputWidth = widthInput.toDouble(&ok);
|
||||||
bool heightFromInput = false;
|
if (ok) widthFromInput = true;
|
||||||
double inputWidth = 0, inputHeight = 0;
|
}
|
||||||
|
if (!heightInput.isEmpty()) {
|
||||||
if (!widthInput.isEmpty()) {
|
bool ok;
|
||||||
bool ok;
|
inputHeight = heightInput.toDouble(&ok);
|
||||||
inputWidth = widthInput.toDouble(&ok);
|
if (ok) heightFromInput = true;
|
||||||
if (ok) widthFromInput = true;
|
|
||||||
}
|
|
||||||
if (!heightInput.isEmpty()) {
|
|
||||||
bool ok;
|
|
||||||
inputHeight = heightInput.toDouble(&ok);
|
|
||||||
if (ok) heightFromInput = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVector3D mousePosQ = m_viewport->unproject(m_viewport->currentMousePos(), plane);
|
|
||||||
gp_Pnt mousePos(mousePosQ.x(), mousePosQ.y(), mousePosQ.z());
|
|
||||||
|
|
||||||
if (widthFromInput || heightFromInput) {
|
|
||||||
gp_Pnt2d startPos2d(gp_Vec(plane.Location(), p1_3d).Dot(plane.XDirection()), gp_Vec(plane.Location(), p1_3d).Dot(plane.YDirection()));
|
|
||||||
gp_Pnt2d mousePos2d(gp_Vec(plane.Location(), mousePos).Dot(plane.XDirection()), gp_Vec(plane.Location(), mousePos).Dot(plane.YDirection()));
|
|
||||||
|
|
||||||
double current_w = qAbs(mousePos2d.X() - startPos2d.X());
|
|
||||||
double current_h = qAbs(mousePos2d.Y() - startPos2d.Y());
|
|
||||||
|
|
||||||
double rect_w = widthFromInput ? inputWidth : current_w;
|
|
||||||
double rect_h = heightFromInput ? inputHeight : current_h;
|
|
||||||
int signX = (mousePos2d.X() >= startPos2d.X()) ? 1 : -1;
|
|
||||||
int signY = (mousePos2d.Y() >= startPos2d.Y()) ? 1 : -1;
|
|
||||||
|
|
||||||
gp_Pnt2d endPos2d(startPos2d.X() + signX * rect_w, startPos2d.Y() + signY * rect_h);
|
|
||||||
gp_Pnt endPos3d = ElCLib::To3d(plane, endPos2d);
|
|
||||||
worldPosQ = QVector3D(endPos3d.X(), endPos3d.Y(), endPos3d.Z());
|
|
||||||
} else {
|
|
||||||
worldPosQ = mousePosQ;
|
|
||||||
if (m_viewport->isSnappingOrigin()) {
|
|
||||||
const auto& origin = plane.Location();
|
|
||||||
worldPosQ.setX(origin.X()); worldPosQ.setY(origin.Y()); worldPosQ.setZ(origin.Z());
|
|
||||||
} else if (m_viewport->isSnappingVertex()) {
|
|
||||||
worldPosQ.setX(m_viewport->snapVertex().X()); worldPosQ.setY(m_viewport->snapVertex().Y()); worldPosQ.setZ(m_viewport->snapVertex().Z());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
gp_Pnt p3_3d(worldPosQ.x(), worldPosQ.y(), worldPosQ.z());
|
|
||||||
gp_Pnt p2_3d, p4_3d;
|
|
||||||
|
|
||||||
gp_Pnt2d p1_2d(gp_Vec(plane.Location(), p1_3d).Dot(plane.XDirection()), gp_Vec(plane.Location(), p1_3d).Dot(plane.YDirection()));
|
QVector3D mousePos = m_viewport->unproject(m_viewport->currentMousePos(), m_viewport->currentPlane());
|
||||||
gp_Pnt2d p3_2d(gp_Vec(plane.Location(), p3_3d).Dot(plane.XDirection()), gp_Vec(plane.Location(), p3_3d).Dot(plane.YDirection()));
|
|
||||||
gp_Pnt2d p2_2d(p3_2d.X(), p1_2d.Y());
|
|
||||||
p2_3d = ElCLib::To3d(plane, p2_2d);
|
|
||||||
|
|
||||||
double w = qAbs(p3_2d.X() - p1_2d.X());
|
if (widthFromInput || heightFromInput) {
|
||||||
double h = qAbs(p3_2d.Y() - p1_2d.Y());
|
QVector3D mouseDir = mousePos - p1_3d;
|
||||||
|
double current_w, current_h;
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
QFontMetrics fm(painter.font());
|
current_w = qAbs(mouseDir.x());
|
||||||
|
current_h = qAbs(mouseDir.z());
|
||||||
QVector3D p1_q(p1_3d.X(), p1_3d.Y(), p1_3d.Z());
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
QVector3D p2_q(p2_3d.X(), p2_3d.Y(), p2_3d.Z());
|
current_w = qAbs(mouseDir.x());
|
||||||
QVector3D p3_q(p3_3d.X(), p3_3d.Y(), p3_3d.Z());
|
current_h = qAbs(mouseDir.y());
|
||||||
|
} else { // YZ
|
||||||
// Width dimension
|
current_w = qAbs(mouseDir.y());
|
||||||
QVector3D widthTextPos3D = (p1_q + p2_q) / 2.0f;
|
current_h = qAbs(mouseDir.z());
|
||||||
QVector3D screenPosW = m_viewport->project(widthTextPos3D, modelView, projection, m_viewport->rect());
|
}
|
||||||
if (screenPosW.z() < 1.0f) {
|
double rect_w = widthFromInput ? inputWidth : current_w;
|
||||||
QString widthText = widthFromInput ? widthInput : QString::number(w, 'f', 2);
|
double rect_h = heightFromInput ? inputHeight : current_h;
|
||||||
QRect textRect = fm.boundingRect(widthText + "__");
|
int signX = (mouseDir.x() >= 0) ? 1 : -1;
|
||||||
textRect.moveCenter(screenPosW.toPoint() + QPoint(0, (p3_2d.Y() > p1_2d.Y()) ? -15 : 15));
|
int signY = (mouseDir.y() >= 0) ? 1 : -1;
|
||||||
if (m_viewport->property("dimensionEditMode").toString() == "width") {
|
int signZ = (mouseDir.z() >= 0) ? 1 : -1;
|
||||||
painter.fillRect(textRect.adjusted(-4, -2, 4, 2), QColor(64, 128, 255));
|
worldPos = p1_3d;
|
||||||
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
|
worldPos.setX(p1_3d.x() + signX * rect_w);
|
||||||
|
worldPos.setZ(p1_3d.z() + signZ * rect_h);
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
|
worldPos.setX(p1_3d.x() + signX * rect_w);
|
||||||
|
worldPos.setY(p1_3d.y() + signY * rect_h);
|
||||||
|
} else { // YZ
|
||||||
|
worldPos.setY(p1_3d.y() + signY * rect_w);
|
||||||
|
worldPos.setZ(p1_3d.z() + signZ * rect_h);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
painter.fillRect(textRect.adjusted(-4, -2, 4, 2), QColor(50, 50, 50));
|
worldPos = mousePos;
|
||||||
|
if (m_viewport->isSnappingOrigin()) {
|
||||||
|
worldPos.setX(0); worldPos.setY(0); worldPos.setZ(0);
|
||||||
|
} else if (m_viewport->isSnappingVertex()) {
|
||||||
|
worldPos.setX(m_viewport->snapVertex().X()); worldPos.setY(m_viewport->snapVertex().Y()); worldPos.setZ(m_viewport->snapVertex().Z());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
painter.setPen(Qt::white);
|
QVector3D p3_3d = worldPos;
|
||||||
painter.drawText(textRect, Qt::AlignCenter, widthText);
|
QVector3D p2_3d, p4_3d;
|
||||||
}
|
|
||||||
|
|
||||||
// Height dimension
|
double w, h;
|
||||||
QVector3D heightTextPos3D = (p2_q + p3_q) / 2.0f;
|
|
||||||
QVector3D screenPosH = m_viewport->project(heightTextPos3D, modelView, projection, m_viewport->rect());
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
if (screenPosH.z() < 1.0f) {
|
p2_3d.setX(p3_3d.x()); p2_3d.setY(p1_3d.y()); p2_3d.setZ(p1_3d.z());
|
||||||
QString heightText = heightFromInput ? heightInput : QString::number(h, 'f', 2);
|
p4_3d.setX(p1_3d.x()); p4_3d.setY(p1_3d.y()); p4_3d.setZ(p3_3d.z());
|
||||||
QRect textRect = fm.boundingRect(heightText + "__");
|
w = qAbs(p3_3d.x() - p1_3d.x());
|
||||||
textRect.moveCenter(screenPosH.toPoint() + QPoint((p3_2d.X() > p1_2d.X()) ? 15 : -15, 0));
|
h = qAbs(p3_3d.z() - p1_3d.z());
|
||||||
if (m_viewport->property("dimensionEditMode").toString() == "height") {
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
painter.fillRect(textRect.adjusted(-4, -2, 4, 2), QColor(64, 128, 255));
|
p2_3d.setX(p3_3d.x()); p2_3d.setY(p1_3d.y()); p2_3d.setZ(p1_3d.z());
|
||||||
} else {
|
p4_3d.setX(p1_3d.x()); p4_3d.setY(p3_3d.y()); p4_3d.setZ(p1_3d.z());
|
||||||
painter.fillRect(textRect.adjusted(-4, -2, 4, 2), QColor(50, 50, 50));
|
w = qAbs(p3_3d.x() - p1_3d.x());
|
||||||
|
h = qAbs(p3_3d.y() - p1_3d.y());
|
||||||
|
} else { // YZ
|
||||||
|
p2_3d.setX(p1_3d.x()); p2_3d.setY(p3_3d.y()); p2_3d.setZ(p1_3d.z());
|
||||||
|
p4_3d.setX(p1_3d.x()); p4_3d.setY(p1_3d.y()); p4_3d.setZ(p3_3d.z());
|
||||||
|
w = qAbs(p3_3d.y() - p1_3d.y());
|
||||||
|
h = qAbs(p3_3d.z() - p1_3d.z());
|
||||||
|
}
|
||||||
|
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
QFontMetrics fm(painter.font());
|
||||||
|
|
||||||
|
// Width dimension
|
||||||
|
QVector3D widthTextPos3D = (p1_3d + p2_3d) / 2.0f;
|
||||||
|
QVector3D screenPosW = m_viewport->project(widthTextPos3D, modelView, projection, m_viewport->rect());
|
||||||
|
if (screenPosW.z() < 1.0f) {
|
||||||
|
QString widthText = widthFromInput ? widthInput : QString::number(w, 'f', 2);
|
||||||
|
QRect textRect = fm.boundingRect(widthText + "__");
|
||||||
|
textRect.moveCenter(screenPosW.toPoint() + QPoint(0, (p3_3d.z() > p1_3d.z() || p3_3d.y() > p1_3d.y()) ? -15 : 15));
|
||||||
|
if (m_viewport->property("dimensionEditMode").toString() == "width") {
|
||||||
|
painter.fillRect(textRect.adjusted(-4, -2, 4, 2), QColor(64, 128, 255));
|
||||||
|
} else {
|
||||||
|
painter.fillRect(textRect.adjusted(-4, -2, 4, 2), QColor(50, 50, 50));
|
||||||
|
}
|
||||||
|
painter.setPen(Qt::white);
|
||||||
|
painter.drawText(textRect, Qt::AlignCenter, widthText);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Height dimension
|
||||||
|
QVector3D heightTextPos3D = (p2_3d + p3_3d) / 2.0f;
|
||||||
|
QVector3D screenPosH = m_viewport->project(heightTextPos3D, modelView, projection, m_viewport->rect());
|
||||||
|
if (screenPosH.z() < 1.0f) {
|
||||||
|
QString heightText = heightFromInput ? heightInput : QString::number(h, 'f', 2);
|
||||||
|
QRect textRect = fm.boundingRect(heightText + "__");
|
||||||
|
textRect.moveCenter(screenPosH.toPoint() + QPoint((p3_3d.x() > p1_3d.x()) ? 15 : -15, 0));
|
||||||
|
if (m_viewport->property("dimensionEditMode").toString() == "height") {
|
||||||
|
painter.fillRect(textRect.adjusted(-4, -2, 4, 2), QColor(64, 128, 255));
|
||||||
|
} else {
|
||||||
|
painter.fillRect(textRect.adjusted(-4, -2, 4, 2), QColor(50, 50, 50));
|
||||||
|
}
|
||||||
|
painter.setPen(Qt::white);
|
||||||
|
painter.drawText(textRect, Qt::AlignCenter, heightText);
|
||||||
}
|
}
|
||||||
painter.setPen(Qt::white);
|
|
||||||
painter.drawText(textRect, Qt::AlignCenter, heightText);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef RECTANGLETOOL_H
|
#ifndef RECTANGLETOOL_H
|
||||||
#define RECTANGLETOOL_H
|
#define RECTANGLETOOL_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "SketchCircle.h"
|
#include "SketchCircle.h"
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef SKETCHCIRCLE_H
|
#ifndef SKETCHCIRCLE_H
|
||||||
#define SKETCHCIRCLE_H
|
#define SKETCHCIRCLE_H
|
||||||
|
|
||||||
|
|||||||
+138
-67
@@ -1,53 +1,29 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "SketchFeature.h"
|
#include "SketchFeature.h"
|
||||||
#include "SketchObject.h"
|
#include "SketchObject.h"
|
||||||
#include "SketchLine.h"
|
#include "SketchLine.h"
|
||||||
#include "SketchRectangle.h"
|
#include "SketchRectangle.h"
|
||||||
|
#include "SketchCircle.h"
|
||||||
|
|
||||||
|
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||||
|
#include <BRepBuilderAPI_MakeWire.hxx>
|
||||||
|
#include <BRepBuilderAPI_MakeFace.hxx>
|
||||||
#include <BRep_Builder.hxx>
|
#include <BRep_Builder.hxx>
|
||||||
#include <TopoDS_Compound.hxx>
|
#include <TopoDS_Compound.hxx>
|
||||||
#include <gp_Pnt.hxx>
|
#include <TopoDS.hxx>
|
||||||
#include <gp_Dir.hxx>
|
#include <gp_Circ.hxx>
|
||||||
|
#include <gp_Ax2.hxx>
|
||||||
|
#include <TopExp_Explorer.hxx>
|
||||||
|
#include <ShapeAnalysis_FreeBounds.hxx>
|
||||||
|
#include <gp_Pln.hxx>
|
||||||
|
#include <BRepOffsetAPI_MakeFilling.hxx>
|
||||||
|
#include <GeomAbs_Shape.hxx>
|
||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonObject>
|
#include <QDebug>
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
void gpPntToJson(const gp_Pnt& p, QJsonObject& json) {
|
|
||||||
json["x"] = p.X();
|
|
||||||
json["y"] = p.Y();
|
|
||||||
json["z"] = p.Z();
|
|
||||||
}
|
|
||||||
|
|
||||||
gp_Pnt jsonToGpPnt(const QJsonObject& json) {
|
|
||||||
return gp_Pnt(json["x"].toDouble(), json["y"].toDouble(), json["z"].toDouble());
|
|
||||||
}
|
|
||||||
|
|
||||||
void gpDirToJson(const gp_Dir& d, QJsonObject& json) {
|
|
||||||
json["x"] = d.X();
|
|
||||||
json["y"] = d.Y();
|
|
||||||
json["z"] = d.Z();
|
|
||||||
}
|
|
||||||
|
|
||||||
gp_Dir jsonToGpDir(const QJsonObject& json) {
|
|
||||||
return gp_Dir(json["x"].toDouble(), json["y"].toDouble(), json["z"].toDouble());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SketchFeature::SketchFeature(const QString& name)
|
SketchFeature::SketchFeature(const QString& name)
|
||||||
: Feature(name), m_plane(gp_Pnt(0, 0, 0), gp::DZ())
|
: Feature(name)
|
||||||
{
|
{
|
||||||
BRep_Builder builder;
|
|
||||||
TopoDS_Compound compound;
|
|
||||||
builder.MakeCompound(compound);
|
|
||||||
m_shape = compound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SketchFeature::~SketchFeature()
|
SketchFeature::~SketchFeature()
|
||||||
@@ -60,12 +36,12 @@ QString SketchFeature::type() const
|
|||||||
return "Sketch";
|
return "Sketch";
|
||||||
}
|
}
|
||||||
|
|
||||||
void SketchFeature::setPlane(const gp_Ax2& plane)
|
void SketchFeature::setPlane(SketchPlane plane)
|
||||||
{
|
{
|
||||||
m_plane = plane;
|
m_plane = plane;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gp_Ax2& SketchFeature::plane() const
|
SketchFeature::SketchPlane SketchFeature::plane() const
|
||||||
{
|
{
|
||||||
return m_plane;
|
return m_plane;
|
||||||
}
|
}
|
||||||
@@ -75,10 +51,117 @@ const TopoDS_Shape& SketchFeature::shape() const
|
|||||||
return m_shape;
|
return m_shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SketchFeature::addShape(const TopoDS_Shape& shape)
|
void SketchFeature::buildShape()
|
||||||
{
|
{
|
||||||
BRep_Builder builder;
|
m_shape.Nullify();
|
||||||
builder.Add(m_shape, shape);
|
QList<TopoDS_Edge> lineEdges;
|
||||||
|
QList<TopoDS_Face> faces;
|
||||||
|
|
||||||
|
gp_Pln sketchPlane;
|
||||||
|
switch (m_plane) {
|
||||||
|
case SketchPlane::XY: sketchPlane = gp_Pln(gp::Origin(), gp::DY()); break;
|
||||||
|
case SketchPlane::XZ: sketchPlane = gp_Pln(gp::Origin(), gp::DZ()); break;
|
||||||
|
case SketchPlane::YZ: sketchPlane = gp_Pln(gp::Origin(), gp::DX()); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (SketchObject* obj : m_objects) {
|
||||||
|
if (auto line = dynamic_cast<SketchLine*>(obj)) {
|
||||||
|
BRepBuilderAPI_MakeEdge makeEdge(line->startPoint(), line->endPoint());
|
||||||
|
if (makeEdge.IsDone()) {
|
||||||
|
lineEdges.append(makeEdge.Edge());
|
||||||
|
}
|
||||||
|
} else if (auto rect = dynamic_cast<SketchRectangle*>(obj)) {
|
||||||
|
const gp_Pnt& c1 = rect->corner1();
|
||||||
|
const gp_Pnt& c2 = rect->corner2();
|
||||||
|
gp_Pnt other_corner1, other_corner2;
|
||||||
|
|
||||||
|
if (m_plane == SketchPlane::XY) {
|
||||||
|
other_corner1.SetCoord(c2.X(), c1.Y(), c1.Z());
|
||||||
|
other_corner2.SetCoord(c1.X(), c1.Y(), c2.Z());
|
||||||
|
} else if (m_plane == SketchPlane::XZ) {
|
||||||
|
other_corner1.SetCoord(c2.X(), c1.Y(), c1.Z());
|
||||||
|
other_corner2.SetCoord(c1.X(), c2.Y(), c1.Z());
|
||||||
|
} else { // YZ
|
||||||
|
other_corner1.SetCoord(c1.X(), c2.Y(), c1.Z());
|
||||||
|
other_corner2.SetCoord(c1.X(), c1.Y(), c2.Z());
|
||||||
|
}
|
||||||
|
|
||||||
|
BRepBuilderAPI_MakeEdge me1(c1, other_corner1);
|
||||||
|
BRepBuilderAPI_MakeEdge me2(other_corner1, c2);
|
||||||
|
BRepBuilderAPI_MakeEdge me3(c2, other_corner2);
|
||||||
|
BRepBuilderAPI_MakeEdge me4(other_corner2, c1);
|
||||||
|
if (me1.IsDone() && me2.IsDone() && me3.IsDone() && me4.IsDone()) {
|
||||||
|
BRepBuilderAPI_MakeWire wireBuilder(me1.Edge(), me2.Edge(), me3.Edge(), me4.Edge());
|
||||||
|
if (wireBuilder.IsDone()) {
|
||||||
|
BRepBuilderAPI_MakeFace faceBuilder(sketchPlane, wireBuilder.Wire());
|
||||||
|
if (faceBuilder.IsDone()) {
|
||||||
|
faces.append(faceBuilder.Face());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (auto circle = dynamic_cast<SketchCircle*>(obj)) {
|
||||||
|
const gp_Pnt& center = circle->center();
|
||||||
|
double radius = circle->radius();
|
||||||
|
gp_Dir normal;
|
||||||
|
switch (m_plane) {
|
||||||
|
case SketchPlane::XY: normal = gp::DY(); break;
|
||||||
|
case SketchPlane::XZ: normal = gp::DZ(); break;
|
||||||
|
case SketchPlane::YZ: normal = gp::DX(); break;
|
||||||
|
}
|
||||||
|
gp_Ax2 axis(center, normal);
|
||||||
|
gp_Circ circ(axis, radius);
|
||||||
|
BRepBuilderAPI_MakeEdge makeEdge(circ);
|
||||||
|
if (makeEdge.IsDone()) {
|
||||||
|
TopoDS_Edge edge = makeEdge.Edge();
|
||||||
|
BRepBuilderAPI_MakeWire wireBuilder(edge);
|
||||||
|
if(wireBuilder.IsDone()) {
|
||||||
|
BRepBuilderAPI_MakeFace faceBuilder(sketchPlane, wireBuilder.Wire());
|
||||||
|
if (faceBuilder.IsDone()) {
|
||||||
|
faces.append(faceBuilder.Face());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lineEdges.isEmpty()) {
|
||||||
|
qDebug() << "buildShape: processing" << lineEdges.size() << "line edges";
|
||||||
|
|
||||||
|
BRepOffsetAPI_MakeFilling faceMaker;
|
||||||
|
for (const TopoDS_Edge& edge : lineEdges) {
|
||||||
|
faceMaker.Add(edge, GeomAbs_C0);
|
||||||
|
}
|
||||||
|
faceMaker.Build();
|
||||||
|
|
||||||
|
if (faceMaker.IsDone()) {
|
||||||
|
TopExp_Explorer explorer(faceMaker.Shape(), TopAbs_FACE);
|
||||||
|
int facesAdded = 0;
|
||||||
|
for (; explorer.More(); explorer.Next()) {
|
||||||
|
faces.append(TopoDS::Face(explorer.Current()));
|
||||||
|
facesAdded++;
|
||||||
|
}
|
||||||
|
qDebug() << "buildShape: added" << facesAdded << "face(s) using MakeFilling";
|
||||||
|
} else {
|
||||||
|
qDebug() << "buildShape: MakeFilling failed";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "buildShape: total faces created:" << faces.size();
|
||||||
|
if (faces.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (faces.size() == 1) {
|
||||||
|
m_shape = faces.first();
|
||||||
|
} else {
|
||||||
|
TopoDS_Compound compound;
|
||||||
|
BRep_Builder builder;
|
||||||
|
builder.MakeCompound(compound);
|
||||||
|
for (const auto& face : faces) {
|
||||||
|
builder.Add(compound, face);
|
||||||
|
}
|
||||||
|
m_shape = compound;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SketchFeature::addObject(SketchObject* object)
|
void SketchFeature::addObject(SketchObject* object)
|
||||||
@@ -94,14 +177,11 @@ const QList<SketchObject*>& SketchFeature::objects() const
|
|||||||
void SketchFeature::read(const QJsonObject& json)
|
void SketchFeature::read(const QJsonObject& json)
|
||||||
{
|
{
|
||||||
Feature::read(json);
|
Feature::read(json);
|
||||||
if (json.contains("plane") && json["plane"].isObject()) {
|
if (json.contains("plane") && json["plane"].isString()) {
|
||||||
QJsonObject planeJson = json["plane"].toObject();
|
QString planeStr = json["plane"].toString();
|
||||||
if (planeJson.contains("origin") && planeJson.contains("normal") && planeJson.contains("x_direction")) {
|
if (planeStr == "XY") m_plane = SketchPlane::XY;
|
||||||
gp_Pnt origin = jsonToGpPnt(planeJson["origin"].toObject());
|
else if (planeStr == "XZ") m_plane = SketchPlane::XZ;
|
||||||
gp_Dir normal = jsonToGpDir(planeJson["normal"].toObject());
|
else if (planeStr == "YZ") m_plane = SketchPlane::YZ;
|
||||||
gp_Dir x_dir = jsonToGpDir(planeJson["x_direction"].toObject());
|
|
||||||
m_plane = gp_Ax2(origin, normal, x_dir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.contains("objects") && json["objects"].isArray()) {
|
if (json.contains("objects") && json["objects"].isArray()) {
|
||||||
@@ -129,22 +209,13 @@ void SketchFeature::read(const QJsonObject& json)
|
|||||||
void SketchFeature::write(QJsonObject& json) const
|
void SketchFeature::write(QJsonObject& json) const
|
||||||
{
|
{
|
||||||
Feature::write(json);
|
Feature::write(json);
|
||||||
|
QString planeStr;
|
||||||
QJsonObject planeJson;
|
switch (m_plane) {
|
||||||
|
case SketchPlane::XY: planeStr = "XY"; break;
|
||||||
QJsonObject originJson;
|
case SketchPlane::XZ: planeStr = "XZ"; break;
|
||||||
gpPntToJson(m_plane.Location(), originJson);
|
case SketchPlane::YZ: planeStr = "YZ"; break;
|
||||||
planeJson["origin"] = originJson;
|
}
|
||||||
|
json["plane"] = planeStr;
|
||||||
QJsonObject normalJson;
|
|
||||||
gpDirToJson(m_plane.Direction(), normalJson);
|
|
||||||
planeJson["normal"] = normalJson;
|
|
||||||
|
|
||||||
QJsonObject xDirJson;
|
|
||||||
gpDirToJson(m_plane.XDirection(), xDirJson);
|
|
||||||
planeJson["x_direction"] = xDirJson;
|
|
||||||
|
|
||||||
json["plane"] = planeJson;
|
|
||||||
|
|
||||||
QJsonArray objectsArray;
|
QJsonArray objectsArray;
|
||||||
for (const auto& object : m_objects) {
|
for (const auto& object : m_objects) {
|
||||||
|
|||||||
+11
-12
@@ -1,15 +1,7 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef SKETCHFEATURE_H
|
#ifndef SKETCHFEATURE_H
|
||||||
#define SKETCHFEATURE_H
|
#define SKETCHFEATURE_H
|
||||||
|
|
||||||
#include <TopoDS_Shape.hxx>
|
#include <TopoDS_Shape.hxx>
|
||||||
#include <gp_Ax2.hxx>
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include "Feature.h"
|
#include "Feature.h"
|
||||||
|
|
||||||
@@ -18,16 +10,23 @@ class SketchObject;
|
|||||||
class SketchFeature : public Feature
|
class SketchFeature : public Feature
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum class SketchPlane {
|
||||||
|
XY,
|
||||||
|
XZ,
|
||||||
|
YZ
|
||||||
|
};
|
||||||
|
|
||||||
SketchFeature(const QString& name);
|
SketchFeature(const QString& name);
|
||||||
~SketchFeature();
|
~SketchFeature();
|
||||||
|
|
||||||
QString type() const override;
|
QString type() const override;
|
||||||
|
|
||||||
void setPlane(const gp_Ax2& plane);
|
void setPlane(SketchPlane plane);
|
||||||
const gp_Ax2& plane() const;
|
SketchPlane plane() const;
|
||||||
|
|
||||||
const TopoDS_Shape& shape() const;
|
const TopoDS_Shape& shape() const;
|
||||||
void addShape(const TopoDS_Shape& shape);
|
|
||||||
|
void buildShape();
|
||||||
|
|
||||||
void addObject(SketchObject* object);
|
void addObject(SketchObject* object);
|
||||||
const QList<SketchObject*>& objects() const;
|
const QList<SketchObject*>& objects() const;
|
||||||
@@ -36,7 +35,7 @@ public:
|
|||||||
void write(QJsonObject &json) const override;
|
void write(QJsonObject &json) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
gp_Ax2 m_plane;
|
SketchPlane m_plane;
|
||||||
TopoDS_Shape m_shape;
|
TopoDS_Shape m_shape;
|
||||||
QList<SketchObject*> m_objects;
|
QList<SketchObject*> m_objects;
|
||||||
};
|
};
|
||||||
|
|||||||
+52
-64
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "SketchGrid.h"
|
#include "SketchGrid.h"
|
||||||
#include "ViewportWidget.h"
|
#include "ViewportWidget.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
@@ -13,7 +6,6 @@
|
|||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <gp_Ax2.hxx>
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct GridParams {
|
struct GridParams {
|
||||||
@@ -31,9 +23,9 @@ GridParams getGridParams(float distance)
|
|||||||
} else if (distance > 50.0f) {
|
} else if (distance > 50.0f) {
|
||||||
return { 5.0f, 25.0f, 1000 };
|
return { 5.0f, 25.0f, 1000 };
|
||||||
} else if (distance > 10.0f) {
|
} else if (distance > 10.0f) {
|
||||||
return { 1.0f, 5.0f, 100 };
|
return { 1.0f, 5.0f, 1000 };
|
||||||
} else { // zoomed in
|
} else { // zoomed in
|
||||||
return { 0.2f, 1.0f, 10 };
|
return { 0.2f, 1.0f, 1000 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -63,7 +55,7 @@ void SketchGrid::initializeGL()
|
|||||||
m_vbo.release();
|
m_vbo.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SketchGrid::paintGL(const gp_Ax2& plane, QOpenGLShaderProgram* shaderProgram, int colorLoc)
|
void SketchGrid::paintGL(SketchPlane plane, QOpenGLShaderProgram* shaderProgram, int colorLoc)
|
||||||
{
|
{
|
||||||
GLint previous_vao = 0;
|
GLint previous_vao = 0;
|
||||||
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &previous_vao);
|
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &previous_vao);
|
||||||
@@ -78,19 +70,12 @@ void SketchGrid::paintGL(const gp_Ax2& plane, QOpenGLShaderProgram* shaderProgra
|
|||||||
QOpenGLContext::currentContext()->extraFunctions()->glBindVertexArray(previous_vao);
|
QOpenGLContext::currentContext()->extraFunctions()->glBindVertexArray(previous_vao);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SketchGrid::drawGridLines(const gp_Ax2& plane, QOpenGLShaderProgram* shaderProgram, int colorLoc)
|
void SketchGrid::drawGridLines(SketchPlane plane, QOpenGLShaderProgram* shaderProgram, int colorLoc)
|
||||||
{
|
{
|
||||||
auto params = getGridParams(-m_viewport->camera()->uiCameraDistance());
|
auto params = getGridParams(-m_viewport->camera()->uiCameraDistance());
|
||||||
const float minorIncrement = params.minorIncrement;
|
const float minorIncrement = params.minorIncrement;
|
||||||
const int gridSize = params.gridSize;
|
const int gridSize = params.gridSize;
|
||||||
|
|
||||||
const auto& origin = plane.Location();
|
|
||||||
const auto& xDir = plane.XDirection();
|
|
||||||
const auto& yDir = plane.YDirection();
|
|
||||||
QVector3D originVec(origin.X(), origin.Y(), origin.Z());
|
|
||||||
QVector3D xDirVec(xDir.X(), xDir.Y(), xDir.Z());
|
|
||||||
QVector3D yDirVec(yDir.X(), yDir.Y(), yDir.Z());
|
|
||||||
|
|
||||||
QVector<GLfloat> minorLines;
|
QVector<GLfloat> minorLines;
|
||||||
QVector<GLfloat> majorLines;
|
QVector<GLfloat> majorLines;
|
||||||
|
|
||||||
@@ -101,14 +86,16 @@ void SketchGrid::drawGridLines(const gp_Ax2& plane, QOpenGLShaderProgram* shader
|
|||||||
|
|
||||||
float pos = i * minorIncrement;
|
float pos = i * minorIncrement;
|
||||||
QVector<GLfloat>& current_vector = (i % 5 == 0) ? majorLines : minorLines;
|
QVector<GLfloat>& current_vector = (i % 5 == 0) ? majorLines : minorLines;
|
||||||
|
if (plane == XY) {
|
||||||
QVector3D p1 = originVec + pos * xDirVec - gridSize * yDirVec;
|
current_vector << pos << 0 << -gridSize << pos << 0 << gridSize;
|
||||||
QVector3D p2 = originVec + pos * xDirVec + gridSize * yDirVec;
|
current_vector << -gridSize << 0 << pos << gridSize << 0 << pos;
|
||||||
current_vector << p1.x() << p1.y() << p1.z() << p2.x() << p2.y() << p2.z();
|
} else if (plane == XZ) {
|
||||||
|
current_vector << pos << -gridSize << 0 << pos << gridSize << 0;
|
||||||
QVector3D p3 = originVec - gridSize * xDirVec + pos * yDirVec;
|
current_vector << -gridSize << pos << 0 << gridSize << pos << 0;
|
||||||
QVector3D p4 = originVec + gridSize * xDirVec + pos * yDirVec;
|
} else { // YZ
|
||||||
current_vector << p3.x() << p3.y() << p3.z() << p4.x() << p4.y() << p4.z();
|
current_vector << 0 << pos << -gridSize << 0 << pos << gridSize;
|
||||||
|
current_vector << 0 << -gridSize << pos << 0 << gridSize << pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_vbo.bind();
|
m_vbo.bind();
|
||||||
@@ -126,51 +113,50 @@ void SketchGrid::drawGridLines(const gp_Ax2& plane, QOpenGLShaderProgram* shader
|
|||||||
glDrawArrays(GL_LINES, 0, majorLines.size() / 3);
|
glDrawArrays(GL_LINES, 0, majorLines.size() / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SketchGrid::drawAxes(const gp_Ax2& plane, QOpenGLShaderProgram* shaderProgram, int colorLoc)
|
void SketchGrid::drawAxes(SketchPlane plane, QOpenGLShaderProgram* shaderProgram, int colorLoc)
|
||||||
{
|
{
|
||||||
auto params = getGridParams(-m_viewport->camera()->uiCameraDistance());
|
auto params = getGridParams(-m_viewport->camera()->uiCameraDistance());
|
||||||
const int axisLength = params.gridSize;
|
const int axisLength = params.gridSize;
|
||||||
|
|
||||||
const auto& origin = plane.Location();
|
|
||||||
const auto& xDir = plane.XDirection();
|
|
||||||
const auto& yDir = plane.YDirection();
|
|
||||||
QVector3D originVec(origin.X(), origin.Y(), origin.Z());
|
|
||||||
QVector3D xDirVec(xDir.X(), xDir.Y(), xDir.Z());
|
|
||||||
QVector3D yDirVec(yDir.X(), yDir.Y(), yDir.Z());
|
|
||||||
|
|
||||||
QVector<GLfloat> vertices;
|
QVector<GLfloat> vertices;
|
||||||
|
|
||||||
glLineWidth(2.0f);
|
glLineWidth(2.0f);
|
||||||
m_vbo.bind();
|
m_vbo.bind();
|
||||||
|
|
||||||
// X Axis (Red)
|
// X Axis (Red)
|
||||||
vertices.clear();
|
if (plane == XY || plane == XZ) {
|
||||||
QVector3D p1 = originVec - axisLength * xDirVec;
|
vertices.clear();
|
||||||
QVector3D p2 = originVec + axisLength * xDirVec;
|
vertices << -axisLength << 0 << 0 << axisLength << 0 << 0;
|
||||||
vertices << p1.x() << p1.y() << p1.z() << p2.x() << p2.y() << p2.z();
|
shaderProgram->setUniformValue(colorLoc, QVector4D(1.0f, 0.0f, 0.0f, 1.0f));
|
||||||
shaderProgram->setUniformValue(colorLoc, QVector4D(1.0f, 0.0f, 0.0f, 1.0f));
|
m_vbo.allocate(vertices.constData(), vertices.size() * sizeof(GLfloat));
|
||||||
m_vbo.allocate(vertices.constData(), vertices.size() * sizeof(GLfloat));
|
glDrawArrays(GL_LINES, 0, 2);
|
||||||
glDrawArrays(GL_LINES, 0, 2);
|
}
|
||||||
|
|
||||||
// Y Axis (Green)
|
// Y Axis (Green)
|
||||||
vertices.clear();
|
if (plane == XY || plane == YZ) {
|
||||||
QVector3D p3 = originVec - axisLength * yDirVec;
|
vertices.clear();
|
||||||
QVector3D p4 = originVec + axisLength * yDirVec;
|
vertices << 0 << 0 << -axisLength << 0 << 0 << axisLength;
|
||||||
vertices << p3.x() << p3.y() << p3.z() << p4.x() << p4.y() << p4.z();
|
shaderProgram->setUniformValue(colorLoc, QVector4D(0.0f, 1.0f, 0.0f, 1.0f));
|
||||||
shaderProgram->setUniformValue(colorLoc, QVector4D(0.0f, 1.0f, 0.0f, 1.0f));
|
m_vbo.allocate(vertices.constData(), vertices.size() * sizeof(GLfloat));
|
||||||
m_vbo.allocate(vertices.constData(), vertices.size() * sizeof(GLfloat));
|
glDrawArrays(GL_LINES, 0, 2);
|
||||||
glDrawArrays(GL_LINES, 0, 2);
|
}
|
||||||
|
// Z Axis (Blue)
|
||||||
|
if (plane == XZ || plane == YZ) {
|
||||||
|
vertices.clear();
|
||||||
|
vertices << 0 << -axisLength << 0 << 0 << axisLength << 0;
|
||||||
|
shaderProgram->setUniformValue(colorLoc, QVector4D(0.0f, 0.0f, 1.0f, 1.0f));
|
||||||
|
m_vbo.allocate(vertices.constData(), vertices.size() * sizeof(GLfloat));
|
||||||
|
glDrawArrays(GL_LINES, 0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
// Origin dot
|
// Origin dot
|
||||||
glPointSize(5.0f);
|
glPointSize(5.0f);
|
||||||
vertices.clear();
|
vertices.clear();
|
||||||
vertices << originVec.x() << originVec.y() << originVec.z();
|
vertices << 0.0f << 0.0f << 0.0f;
|
||||||
shaderProgram->setUniformValue(colorLoc, QVector4D(1.0f, 1.0f, 1.0f, 1.0f)); // White
|
shaderProgram->setUniformValue(colorLoc, QVector4D(1.0f, 1.0f, 1.0f, 1.0f)); // White
|
||||||
m_vbo.allocate(vertices.constData(), vertices.size() * sizeof(GLfloat));
|
m_vbo.allocate(vertices.constData(), vertices.size() * sizeof(GLfloat));
|
||||||
glDrawArrays(GL_POINTS, 0, 1);
|
glDrawArrays(GL_POINTS, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SketchGrid::paintAxisLabels(QPainter& painter, const gp_Ax2& plane, const QMatrix4x4& modelView, const QMatrix4x4& projection)
|
void SketchGrid::paintAxisLabels(QPainter& painter, SketchGrid::SketchPlane plane, const QMatrix4x4& modelView, const QMatrix4x4& projection)
|
||||||
{
|
{
|
||||||
painter.setPen(Qt::white);
|
painter.setPen(Qt::white);
|
||||||
painter.setFont(QFont("Arial", 10));
|
painter.setFont(QFont("Arial", 10));
|
||||||
@@ -179,21 +165,15 @@ void SketchGrid::paintAxisLabels(QPainter& painter, const gp_Ax2& plane, const Q
|
|||||||
const float majorIncrement = params.majorIncrement;
|
const float majorIncrement = params.majorIncrement;
|
||||||
const int range = params.gridSize;
|
const int range = params.gridSize;
|
||||||
|
|
||||||
const auto& origin = plane.Location();
|
auto drawLabelsForAxis = [&](int axis_idx) {
|
||||||
const auto& xDir = plane.XDirection();
|
|
||||||
const auto& yDir = plane.YDirection();
|
|
||||||
QVector3D originVec(origin.X(), origin.Y(), origin.Z());
|
|
||||||
QVector3D xDirVec(xDir.X(), xDir.Y(), xDir.Z());
|
|
||||||
QVector3D yDirVec(yDir.X(), yDir.Y(), yDir.Z());
|
|
||||||
|
|
||||||
auto drawLabelsForAxis = [&](const QVector3D& axisDir) {
|
|
||||||
int numLabels = range / majorIncrement;
|
int numLabels = range / majorIncrement;
|
||||||
for (int i = -numLabels; i <= numLabels; ++i) {
|
for (int i = -numLabels; i <= numLabels; ++i) {
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
float val = i * majorIncrement;
|
float val = i * majorIncrement;
|
||||||
QVector3D worldCoord = originVec + val * axisDir;
|
QVector3D worldCoord;
|
||||||
|
worldCoord[axis_idx] = val;
|
||||||
|
|
||||||
QVector3D screenPos = m_viewport->project(worldCoord, modelView, projection, m_viewport->rect());
|
QVector3D screenPos = m_viewport->project(worldCoord, modelView, projection, m_viewport->rect());
|
||||||
if (screenPos.z() < 1.0f) { // Not clipped
|
if (screenPos.z() < 1.0f) { // Not clipped
|
||||||
@@ -202,6 +182,14 @@ void SketchGrid::paintAxisLabels(QPainter& painter, const gp_Ax2& plane, const Q
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
drawLabelsForAxis(xDirVec);
|
if (plane == SketchGrid::XY) {
|
||||||
drawLabelsForAxis(yDirVec);
|
drawLabelsForAxis(0); // X
|
||||||
|
drawLabelsForAxis(2); // Y
|
||||||
|
} else if (plane == SketchGrid::XZ) {
|
||||||
|
drawLabelsForAxis(0); // X
|
||||||
|
drawLabelsForAxis(1); // Z
|
||||||
|
} else if (plane == SketchGrid::YZ) {
|
||||||
|
drawLabelsForAxis(1); // Y
|
||||||
|
drawLabelsForAxis(2); // Z
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-12
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef SKETCHGRID_H
|
#ifndef SKETCHGRID_H
|
||||||
#define SKETCHGRID_H
|
#define SKETCHGRID_H
|
||||||
|
|
||||||
@@ -12,7 +5,6 @@
|
|||||||
#include <QMatrix4x4>
|
#include <QMatrix4x4>
|
||||||
#include <QOpenGLVertexArrayObject>
|
#include <QOpenGLVertexArrayObject>
|
||||||
#include <QOpenGLBuffer>
|
#include <QOpenGLBuffer>
|
||||||
#include <gp_Ax2.hxx>
|
|
||||||
|
|
||||||
class QOpenGLShaderProgram;
|
class QOpenGLShaderProgram;
|
||||||
class QPainter;
|
class QPainter;
|
||||||
@@ -21,16 +13,22 @@ class ViewportWidget;
|
|||||||
class SketchGrid : protected QOpenGLFunctions
|
class SketchGrid : protected QOpenGLFunctions
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum SketchPlane {
|
||||||
|
XY = 1,
|
||||||
|
XZ = 2,
|
||||||
|
YZ = 3
|
||||||
|
};
|
||||||
|
|
||||||
explicit SketchGrid(ViewportWidget* viewport);
|
explicit SketchGrid(ViewportWidget* viewport);
|
||||||
~SketchGrid();
|
~SketchGrid();
|
||||||
|
|
||||||
void initializeGL();
|
void initializeGL();
|
||||||
void paintGL(const gp_Ax2& plane, QOpenGLShaderProgram* shaderProgram, int colorLoc);
|
void paintGL(SketchPlane plane, QOpenGLShaderProgram* shaderProgram, int colorLoc);
|
||||||
void paintAxisLabels(QPainter& painter, const gp_Ax2& plane, const QMatrix4x4& modelView, const QMatrix4x4& projection);
|
void paintAxisLabels(QPainter& painter, SketchPlane plane, const QMatrix4x4& modelView, const QMatrix4x4& projection);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void drawGridLines(const gp_Ax2& plane, QOpenGLShaderProgram* shaderProgram, int colorLoc);
|
void drawGridLines(SketchPlane plane, QOpenGLShaderProgram* shaderProgram, int colorLoc);
|
||||||
void drawAxes(const gp_Ax2& plane, QOpenGLShaderProgram* shaderProgram, int colorLoc);
|
void drawAxes(SketchPlane plane, QOpenGLShaderProgram* shaderProgram, int colorLoc);
|
||||||
|
|
||||||
QOpenGLVertexArrayObject m_vao;
|
QOpenGLVertexArrayObject m_vao;
|
||||||
QOpenGLBuffer m_vbo;
|
QOpenGLBuffer m_vbo;
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "SketchLine.h"
|
#include "SketchLine.h"
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef SKETCHLINE_H
|
#ifndef SKETCHLINE_H
|
||||||
#define SKETCHLINE_H
|
#define SKETCHLINE_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef SKETCHOBJECT_H
|
#ifndef SKETCHOBJECT_H
|
||||||
#define SKETCHOBJECT_H
|
#define SKETCHOBJECT_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "SketchRectangle.h"
|
#include "SketchRectangle.h"
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef SKETCHRECTANGLE_H
|
#ifndef SKETCHRECTANGLE_H
|
||||||
#define SKETCHRECTANGLE_H
|
#define SKETCHRECTANGLE_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "SketchTool.h"
|
#include "SketchTool.h"
|
||||||
#include "ViewportWidget.h"
|
#include "ViewportWidget.h"
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef SKETCHTOOL_H
|
#ifndef SKETCHTOOL_H
|
||||||
#define SKETCHTOOL_H
|
#define SKETCHTOOL_H
|
||||||
|
|
||||||
|
|||||||
+90
-69
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "Snapping.h"
|
#include "Snapping.h"
|
||||||
|
|
||||||
#include "ViewportWidget.h"
|
#include "ViewportWidget.h"
|
||||||
@@ -19,11 +12,6 @@
|
|||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <optional>
|
|
||||||
#include <gp_Ax2.hxx>
|
|
||||||
#include <gp_Pnt2d.hxx>
|
|
||||||
#include <gp_Vec.hxx>
|
|
||||||
#include <ElCLib.hxx>
|
|
||||||
|
|
||||||
Snapping::Snapping(ViewportWidget* viewport) : m_viewport(viewport)
|
Snapping::Snapping(ViewportWidget* viewport) : m_viewport(viewport)
|
||||||
{
|
{
|
||||||
@@ -35,15 +23,23 @@ bool Snapping::update(const QPoint& mousePos)
|
|||||||
bool oldIsSnappingVertex = m_isSnappingVertex;
|
bool oldIsSnappingVertex = m_isSnappingVertex;
|
||||||
|
|
||||||
bool shouldSnap = false;
|
bool shouldSnap = false;
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
if (m_viewport->currentPlane() != ViewportWidget::SketchPlane::NONE && m_viewport->activeTool() != static_cast<int>(ApplicationController::ToolType::None)) {
|
||||||
if (currentPlaneOpt && m_viewport->activeTool() != static_cast<int>(ApplicationController::ToolType::None)) {
|
QVector3D worldPos = m_viewport->unproject(mousePos, m_viewport->currentPlane());
|
||||||
const auto& plane = currentPlaneOpt.value();
|
|
||||||
QVector3D worldPosQ = m_viewport->unproject(mousePos, plane);
|
|
||||||
gp_Pnt worldPos(worldPosQ.x(), worldPosQ.y(), worldPosQ.z());
|
|
||||||
const float snapRectHalfSize = 0.0075f * -m_viewport->camera()->zoom();
|
const float snapRectHalfSize = 0.0075f * -m_viewport->camera()->zoom();
|
||||||
|
|
||||||
gp_Pnt2d worldPos2d(gp_Vec(plane.Location(), worldPos).Dot(plane.XDirection()), gp_Vec(plane.Location(), worldPos).Dot(plane.YDirection()));
|
switch (m_viewport->currentPlane()) {
|
||||||
shouldSnap = qAbs(worldPos2d.X()) < snapRectHalfSize && qAbs(worldPos2d.Y()) < snapRectHalfSize;
|
case ViewportWidget::SketchPlane::XY:
|
||||||
|
shouldSnap = qAbs(worldPos.x()) < snapRectHalfSize && qAbs(worldPos.z()) < snapRectHalfSize;
|
||||||
|
break;
|
||||||
|
case ViewportWidget::SketchPlane::XZ:
|
||||||
|
shouldSnap = qAbs(worldPos.x()) < snapRectHalfSize && qAbs(worldPos.y()) < snapRectHalfSize;
|
||||||
|
break;
|
||||||
|
case ViewportWidget::SketchPlane::YZ:
|
||||||
|
shouldSnap = qAbs(worldPos.y()) < snapRectHalfSize && qAbs(worldPos.z()) < snapRectHalfSize;
|
||||||
|
break;
|
||||||
|
case ViewportWidget::SketchPlane::NONE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_isSnappingOrigin = shouldSnap;
|
m_isSnappingOrigin = shouldSnap;
|
||||||
@@ -52,11 +48,8 @@ bool Snapping::update(const QPoint& mousePos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_isSnappingVertex = false;
|
m_isSnappingVertex = false;
|
||||||
if (!m_isSnappingOrigin && m_viewport->document() && currentPlaneOpt && m_viewport->activeTool() != static_cast<int>(ApplicationController::ToolType::None)) {
|
if (!m_isSnappingOrigin && m_viewport->document() && m_viewport->currentPlane() != ViewportWidget::SketchPlane::NONE && m_viewport->activeTool() != static_cast<int>(ApplicationController::ToolType::None)) {
|
||||||
const auto& plane = currentPlaneOpt.value();
|
QVector3D worldPos = m_viewport->unproject(mousePos, m_viewport->currentPlane());
|
||||||
QVector3D worldPosQ = m_viewport->unproject(mousePos, plane);
|
|
||||||
gp_Pnt worldPos(worldPosQ.x(), worldPosQ.y(), worldPosQ.z());
|
|
||||||
gp_Pnt2d worldPos2d(gp_Vec(plane.Location(), worldPos).Dot(plane.XDirection()), gp_Vec(plane.Location(), worldPos).Dot(plane.YDirection()));
|
|
||||||
const float snapRectHalfSize = 0.0075f * -m_viewport->camera()->zoom();
|
const float snapRectHalfSize = 0.0075f * -m_viewport->camera()->zoom();
|
||||||
|
|
||||||
for (Feature* feature : m_viewport->document()->features()) {
|
for (Feature* feature : m_viewport->document()->features()) {
|
||||||
@@ -66,8 +59,20 @@ bool Snapping::update(const QPoint& mousePos)
|
|||||||
auto line = static_cast<const SketchLine*>(obj);
|
auto line = static_cast<const SketchLine*>(obj);
|
||||||
const gp_Pnt vertices[] = {line->startPoint(), line->endPoint()};
|
const gp_Pnt vertices[] = {line->startPoint(), line->endPoint()};
|
||||||
for (const auto& vertex : vertices) {
|
for (const auto& vertex : vertices) {
|
||||||
gp_Pnt2d vertex2d(gp_Vec(plane.Location(), vertex).Dot(plane.XDirection()), gp_Vec(plane.Location(), vertex).Dot(plane.YDirection()));
|
bool isClose = false;
|
||||||
bool isClose = qAbs(worldPos2d.X() - vertex2d.X()) < snapRectHalfSize && qAbs(worldPos2d.Y() - vertex2d.Y()) < snapRectHalfSize;
|
switch (m_viewport->currentPlane()) {
|
||||||
|
case ViewportWidget::SketchPlane::XY:
|
||||||
|
isClose = qAbs(worldPos.x() - vertex.X()) < snapRectHalfSize && qAbs(worldPos.z() - vertex.Z()) < snapRectHalfSize;
|
||||||
|
break;
|
||||||
|
case ViewportWidget::SketchPlane::XZ:
|
||||||
|
isClose = qAbs(worldPos.x() - vertex.X()) < snapRectHalfSize && qAbs(worldPos.y() - vertex.Y()) < snapRectHalfSize;
|
||||||
|
break;
|
||||||
|
case ViewportWidget::SketchPlane::YZ:
|
||||||
|
isClose = qAbs(worldPos.y() - vertex.Y()) < snapRectHalfSize && qAbs(worldPos.z() - vertex.Z()) < snapRectHalfSize;
|
||||||
|
break;
|
||||||
|
case ViewportWidget::SketchPlane::NONE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (isClose) {
|
if (isClose) {
|
||||||
m_isSnappingVertex = true;
|
m_isSnappingVertex = true;
|
||||||
@@ -77,23 +82,37 @@ bool Snapping::update(const QPoint& mousePos)
|
|||||||
}
|
}
|
||||||
} else if (obj->type() == SketchObject::ObjectType::Rectangle) {
|
} else if (obj->type() == SketchObject::ObjectType::Rectangle) {
|
||||||
auto rect = static_cast<const SketchRectangle*>(obj);
|
auto rect = static_cast<const SketchRectangle*>(obj);
|
||||||
const auto& rectPlane = sketch->plane();
|
|
||||||
const auto& p1 = rect->corner1();
|
const auto& p1 = rect->corner1();
|
||||||
const auto& p3 = rect->corner2();
|
const auto& p3 = rect->corner2();
|
||||||
|
gp_Pnt p2, p4;
|
||||||
|
|
||||||
gp_Pnt2d p1_2d(gp_Vec(rectPlane.Location(), p1).Dot(rectPlane.XDirection()), gp_Vec(rectPlane.Location(), p1).Dot(rectPlane.YDirection()));
|
if (sketch->plane() == SketchFeature::SketchPlane::XY) {
|
||||||
gp_Pnt2d p3_2d(gp_Vec(rectPlane.Location(), p3).Dot(rectPlane.XDirection()), gp_Vec(rectPlane.Location(), p3).Dot(rectPlane.YDirection()));
|
p2.SetCoord(p3.X(), p1.Y(), p1.Z());
|
||||||
|
p4.SetCoord(p1.X(), p1.Y(), p3.Z());
|
||||||
gp_Pnt2d p2_2d(p3_2d.X(), p1_2d.Y());
|
} else if (sketch->plane() == SketchFeature::SketchPlane::XZ) {
|
||||||
gp_Pnt2d p4_2d(p1_2d.X(), p3_2d.Y());
|
p2.SetCoord(p3.X(), p1.Y(), p1.Z());
|
||||||
|
p4.SetCoord(p1.X(), p3.Y(), p1.Z());
|
||||||
gp_Pnt p2 = ElCLib::To3d(rectPlane, p2_2d);
|
} else if (sketch->plane() == SketchFeature::SketchPlane::YZ) {
|
||||||
gp_Pnt p4 = ElCLib::To3d(rectPlane, p4_2d);
|
p2.SetCoord(p1.X(), p3.Y(), p1.Z());
|
||||||
|
p4.SetCoord(p1.X(), p1.Y(), p3.Z());
|
||||||
|
}
|
||||||
|
|
||||||
const gp_Pnt vertices[] = {p1, p2, p3, p4};
|
const gp_Pnt vertices[] = {p1, p2, p3, p4};
|
||||||
for (const auto& vertex : vertices) {
|
for (const auto& vertex : vertices) {
|
||||||
gp_Pnt2d vertex2d(gp_Vec(plane.Location(), vertex).Dot(plane.XDirection()), gp_Vec(plane.Location(), vertex).Dot(plane.YDirection()));
|
bool isClose = false;
|
||||||
bool isClose = qAbs(worldPos2d.X() - vertex2d.X()) < snapRectHalfSize && qAbs(worldPos2d.Y() - vertex2d.Y()) < snapRectHalfSize;
|
switch (m_viewport->currentPlane()) {
|
||||||
|
case ViewportWidget::SketchPlane::XY:
|
||||||
|
isClose = qAbs(worldPos.x() - vertex.X()) < snapRectHalfSize && qAbs(worldPos.z() - vertex.Z()) < snapRectHalfSize;
|
||||||
|
break;
|
||||||
|
case ViewportWidget::SketchPlane::XZ:
|
||||||
|
isClose = qAbs(worldPos.x() - vertex.X()) < snapRectHalfSize && qAbs(worldPos.y() - vertex.Y()) < snapRectHalfSize;
|
||||||
|
break;
|
||||||
|
case ViewportWidget::SketchPlane::YZ:
|
||||||
|
isClose = qAbs(worldPos.y() - vertex.Y()) < snapRectHalfSize && qAbs(worldPos.z() - vertex.Z()) < snapRectHalfSize;
|
||||||
|
break;
|
||||||
|
case ViewportWidget::SketchPlane::NONE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (isClose) {
|
if (isClose) {
|
||||||
m_isSnappingVertex = true;
|
m_isSnappingVertex = true;
|
||||||
@@ -118,41 +137,43 @@ void Snapping::paintGL() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
QVector<GLfloat> vertices;
|
QVector<GLfloat> vertices;
|
||||||
auto currentPlaneOpt = m_viewport->currentPlane();
|
|
||||||
if (!currentPlaneOpt) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto& plane = currentPlaneOpt.value();
|
|
||||||
const auto& xDir = plane.XDirection();
|
|
||||||
const auto& yDir = plane.YDirection();
|
|
||||||
QVector3D X(xDir.X(), xDir.Y(), xDir.Z());
|
|
||||||
QVector3D Y(yDir.X(), yDir.Y(), yDir.Z());
|
|
||||||
const float rectSize = 0.0075f * -m_viewport->camera()->zoom();
|
|
||||||
|
|
||||||
if (m_isSnappingOrigin) {
|
if (m_isSnappingOrigin) {
|
||||||
const auto& o = plane.Location();
|
const float rectSize = 0.0075f * -m_viewport->camera()->zoom();
|
||||||
QVector3D O(o.X(), o.Y(), o.Z());
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
|
vertices << -rectSize << 0 << -rectSize << rectSize << 0 << -rectSize;
|
||||||
QVector3D p1 = O - rectSize * X - rectSize * Y;
|
vertices << rectSize << 0 << -rectSize << rectSize << 0 << rectSize;
|
||||||
QVector3D p2 = O + rectSize * X - rectSize * Y;
|
vertices << rectSize << 0 << rectSize << -rectSize << 0 << rectSize;
|
||||||
QVector3D p3 = O + rectSize * X + rectSize * Y;
|
vertices << -rectSize << 0 << rectSize << -rectSize << 0 << -rectSize;
|
||||||
QVector3D p4 = O - rectSize * X + rectSize * Y;
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
vertices << p1.x() << p1.y() << p1.z() << p2.x() << p2.y() << p2.z();
|
vertices << -rectSize << -rectSize << 0 << rectSize << -rectSize << 0;
|
||||||
vertices << p2.x() << p2.y() << p2.z() << p3.x() << p3.y() << p3.z();
|
vertices << rectSize << -rectSize << 0 << rectSize << rectSize << 0;
|
||||||
vertices << p3.x() << p3.y() << p3.z() << p4.x() << p4.y() << p4.z();
|
vertices << rectSize << rectSize << 0 << -rectSize << rectSize << 0;
|
||||||
vertices << p4.x() << p4.y() << p4.z() << p1.x() << p1.y() << p1.z();
|
vertices << -rectSize << rectSize << 0 << -rectSize << -rectSize << 0;
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) {
|
||||||
|
vertices << 0 << -rectSize << -rectSize << 0 << rectSize << -rectSize;
|
||||||
|
vertices << 0 << rectSize << -rectSize << 0 << rectSize << rectSize;
|
||||||
|
vertices << 0 << rectSize << rectSize << 0 << -rectSize << rectSize;
|
||||||
|
vertices << 0 << -rectSize << rectSize << 0 << -rectSize << -rectSize;
|
||||||
|
}
|
||||||
} else if (m_isSnappingVertex) {
|
} else if (m_isSnappingVertex) {
|
||||||
|
const float rectSize = 0.0075f * -m_viewport->camera()->zoom();
|
||||||
const auto& v = m_snapVertex;
|
const auto& v = m_snapVertex;
|
||||||
QVector3D V(v.X(), v.Y(), v.Z());
|
if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XY) {
|
||||||
|
vertices << v.X() - rectSize << v.Y() << v.Z() - rectSize << v.X() + rectSize << v.Y() << v.Z() - rectSize;
|
||||||
QVector3D p1 = V - rectSize * X - rectSize * Y;
|
vertices << v.X() + rectSize << v.Y() << v.Z() - rectSize << v.X() + rectSize << v.Y() << v.Z() + rectSize;
|
||||||
QVector3D p2 = V + rectSize * X - rectSize * Y;
|
vertices << v.X() + rectSize << v.Y() << v.Z() + rectSize << v.X() - rectSize << v.Y() << v.Z() + rectSize;
|
||||||
QVector3D p3 = V + rectSize * X + rectSize * Y;
|
vertices << v.X() - rectSize << v.Y() << v.Z() + rectSize << v.X() - rectSize << v.Y() << v.Z() - rectSize;
|
||||||
QVector3D p4 = V - rectSize * X + rectSize * Y;
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::XZ) {
|
||||||
vertices << p1.x() << p1.y() << p1.z() << p2.x() << p2.y() << p2.z();
|
vertices << v.X() - rectSize << v.Y() - rectSize << v.Z() << v.X() + rectSize << v.Y() - rectSize << v.Z();
|
||||||
vertices << p2.x() << p2.y() << p2.z() << p3.x() << p3.y() << p3.z();
|
vertices << v.X() + rectSize << v.Y() - rectSize << v.Z() << v.X() + rectSize << v.Y() + rectSize << v.Z();
|
||||||
vertices << p3.x() << p3.y() << p3.z() << p4.x() << p4.y() << p4.z();
|
vertices << v.X() + rectSize << v.Y() + rectSize << v.Z() << v.X() - rectSize << v.Y() + rectSize << v.Z();
|
||||||
vertices << p4.x() << p4.y() << p4.z() << p1.x() << p1.y() << p1.z();
|
vertices << v.X() - rectSize << v.Y() + rectSize << v.Z() << v.X() - rectSize << v.Y() - rectSize << v.Z();
|
||||||
|
} else if (m_viewport->currentPlane() == ViewportWidget::SketchPlane::YZ) {
|
||||||
|
vertices << v.X() << v.Y() - rectSize << v.Z() - rectSize << v.X() << v.Y() + rectSize << v.Z() - rectSize;
|
||||||
|
vertices << v.X() << v.Y() + rectSize << v.Z() - rectSize << v.X() << v.Y() + rectSize << v.Z() + rectSize;
|
||||||
|
vertices << v.X() << v.Y() + rectSize << v.Z() + rectSize << v.X() << v.Y() - rectSize << v.Z() + rectSize;
|
||||||
|
vertices << v.X() << v.Y() - rectSize << v.Z() + rectSize << v.X() << v.Y() - rectSize << v.Z() - rectSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_viewport->shaderProgram()->setUniformValue(m_viewport->colorLoc(), QVector4D(1.0f, 1.0f, 0.0f, 0.5f));
|
m_viewport->shaderProgram()->setUniformValue(m_viewport->colorLoc(), QVector4D(1.0f, 1.0f, 0.0f, 0.5f));
|
||||||
m_viewport->vbo().bind();
|
m_viewport->vbo().bind();
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef SNAPPING_H
|
#ifndef SNAPPING_H
|
||||||
#define SNAPPING_H
|
#define SNAPPING_H
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "ViewCube.h"
|
#include "ViewCube.h"
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
@@ -14,7 +7,6 @@
|
|||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QSvgRenderer>
|
#include <QSvgRenderer>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QVector3D>
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@@ -82,35 +74,6 @@ void ViewCube::paintGL(QOpenGLShaderProgram* simpleShader, int simpleShaderColor
|
|||||||
drawViewCube(viewCubeProjection, viewMatrix, opacity);
|
drawViewCube(viewCubeProjection, viewMatrix, opacity);
|
||||||
drawAxes(simpleShader, simpleShaderColorLoc, viewCubeProjection, viewMatrix);
|
drawAxes(simpleShader, simpleShaderColorLoc, viewCubeProjection, viewMatrix);
|
||||||
|
|
||||||
QMatrix4x4 mvp = viewCubeProjection * viewMatrix;
|
|
||||||
const float axisLen = 1.7f;
|
|
||||||
|
|
||||||
QVector3D xAxisEnd(axisLen, 0.0f, 0.0f);
|
|
||||||
QVector3D yAxisEnd(0.0f, 0.0f, axisLen);
|
|
||||||
QVector3D zAxisEnd(0.0f, axisLen, 0.0f);
|
|
||||||
|
|
||||||
QVector3D xAxisNdc = mvp.map(xAxisEnd);
|
|
||||||
QVector3D yAxisNdc = mvp.map(yAxisEnd);
|
|
||||||
QVector3D zAxisNdc = mvp.map(zAxisEnd);
|
|
||||||
|
|
||||||
const int vpX = width - viewCubeSize;
|
|
||||||
const int vpY = 0;
|
|
||||||
const int vpW = viewCubeSize;
|
|
||||||
const int vpH = viewCubeSize;
|
|
||||||
const float dpr = QGuiApplication::primaryScreen()->devicePixelRatio();
|
|
||||||
|
|
||||||
m_xAxisLabelPos.setX( (xAxisNdc.x() + 1.0f) * vpW / 2.0f + vpX );
|
|
||||||
m_xAxisLabelPos.setY( (1.0f - xAxisNdc.y()) * vpH / 2.0f + vpY );
|
|
||||||
m_xAxisLabelPos /= dpr;
|
|
||||||
|
|
||||||
m_yAxisLabelPos.setX( (yAxisNdc.x() + 1.0f) * vpW / 2.0f + vpX );
|
|
||||||
m_yAxisLabelPos.setY( (1.0f - yAxisNdc.y()) * vpH / 2.0f + vpY );
|
|
||||||
m_yAxisLabelPos /= dpr;
|
|
||||||
|
|
||||||
m_zAxisLabelPos.setX( (zAxisNdc.x() + 1.0f) * vpW / 2.0f + vpX );
|
|
||||||
m_zAxisLabelPos.setY( (1.0f - zAxisNdc.y()) * vpH / 2.0f + vpY );
|
|
||||||
m_zAxisLabelPos /= dpr;
|
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,23 +229,6 @@ void ViewCube::drawAxes(QOpenGLShaderProgram* simpleShader, int colorLoc, const
|
|||||||
|
|
||||||
void ViewCube::paint2D(QPainter& painter, int widgetWidth, int widgetHeight)
|
void ViewCube::paint2D(QPainter& painter, int widgetWidth, int widgetHeight)
|
||||||
{
|
{
|
||||||
QFont font("Arial", 10, QFont::Bold);
|
|
||||||
painter.setFont(font);
|
|
||||||
painter.setPen(Qt::white);
|
|
||||||
QFontMetrics fm(font);
|
|
||||||
|
|
||||||
QRect xRect = fm.boundingRect("X");
|
|
||||||
xRect.moveCenter(m_xAxisLabelPos);
|
|
||||||
painter.drawText(xRect, Qt::AlignCenter, "X");
|
|
||||||
|
|
||||||
QRect yRect = fm.boundingRect("Y");
|
|
||||||
yRect.moveCenter(m_yAxisLabelPos);
|
|
||||||
painter.drawText(yRect, Qt::AlignCenter, "Y");
|
|
||||||
|
|
||||||
QRect zRect = fm.boundingRect("Z");
|
|
||||||
zRect.moveCenter(m_zAxisLabelPos);
|
|
||||||
painter.drawText(zRect, Qt::AlignCenter, "Z");
|
|
||||||
|
|
||||||
if (!m_isHovered) {
|
if (!m_isHovered) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef VIEWCUBE_H
|
#ifndef VIEWCUBE_H
|
||||||
#define VIEWCUBE_H
|
#define VIEWCUBE_H
|
||||||
|
|
||||||
@@ -41,10 +34,6 @@ private:
|
|||||||
QRect m_homeButtonRect;
|
QRect m_homeButtonRect;
|
||||||
QSvgRenderer* m_homeButtonRenderer = nullptr;
|
QSvgRenderer* m_homeButtonRenderer = nullptr;
|
||||||
|
|
||||||
QPoint m_xAxisLabelPos;
|
|
||||||
QPoint m_yAxisLabelPos;
|
|
||||||
QPoint m_zAxisLabelPos;
|
|
||||||
|
|
||||||
QOpenGLTexture* m_faceTextures[6];
|
QOpenGLTexture* m_faceTextures[6];
|
||||||
|
|
||||||
QOpenGLShaderProgram* m_textureShaderProgram = nullptr;
|
QOpenGLShaderProgram* m_textureShaderProgram = nullptr;
|
||||||
|
|||||||
+200
-107
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include "ViewportWidget.h"
|
#include "ViewportWidget.h"
|
||||||
#include "Snapping.h"
|
#include "Snapping.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
@@ -33,15 +26,18 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <ElCLib.hxx>
|
|
||||||
#include <gp_Pnt2d.hxx>
|
|
||||||
#include <gp_Vec.hxx>
|
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <optional>
|
|
||||||
#include <gp_Ax2.hxx>
|
#include <BRepMesh_IncrementalMesh.hxx>
|
||||||
|
#include <TopExp_Explorer.hxx>
|
||||||
|
#include <TopoDS.hxx>
|
||||||
|
#include <TopoDS_Face.hxx>
|
||||||
|
#include <Poly_Triangulation.hxx>
|
||||||
|
#include <BRep_Tool.hxx>
|
||||||
#include <gp_Dir.hxx>
|
#include <gp_Dir.hxx>
|
||||||
|
#include <gp_Trsf.hxx>
|
||||||
|
|
||||||
struct PntComparator {
|
struct PntComparator {
|
||||||
bool operator()(const gp_Pnt& a, const gp_Pnt& b) const {
|
bool operator()(const gp_Pnt& a, const gp_Pnt& b) const {
|
||||||
@@ -66,7 +62,7 @@ ViewportWidget::ViewportWidget(QWidget *parent)
|
|||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
|
|
||||||
m_currentPlane = gp_Ax2(gp::Origin(), gp::DZ());
|
m_currentPlane = SketchPlane::XY;
|
||||||
|
|
||||||
m_toolIcons.insert(static_cast<int>(ApplicationController::ToolType::Line), new QSvgRenderer(QString(":/icons/line.svg"), this));
|
m_toolIcons.insert(static_cast<int>(ApplicationController::ToolType::Line), new QSvgRenderer(QString(":/icons/line.svg"), this));
|
||||||
m_toolIcons.insert(static_cast<int>(ApplicationController::ToolType::Rectangle), new QSvgRenderer(QString(":/icons/rectangle.svg"), this));
|
m_toolIcons.insert(static_cast<int>(ApplicationController::ToolType::Rectangle), new QSvgRenderer(QString(":/icons/rectangle.svg"), this));
|
||||||
@@ -85,6 +81,7 @@ ViewportWidget::~ViewportWidget()
|
|||||||
{
|
{
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
delete m_shaderProgram;
|
delete m_shaderProgram;
|
||||||
|
delete m_litShaderProgram;
|
||||||
delete m_viewCube;
|
delete m_viewCube;
|
||||||
delete m_sketchGrid;
|
delete m_sketchGrid;
|
||||||
m_vbo.destroy();
|
m_vbo.destroy();
|
||||||
@@ -149,12 +146,12 @@ void ViewportWidget::paintGL()
|
|||||||
|
|
||||||
// Sketch grid rendering
|
// Sketch grid rendering
|
||||||
if (m_isSelectingPlane) {
|
if (m_isSelectingPlane) {
|
||||||
if (m_highlightedPlane) {
|
if (m_highlightedPlane != SketchPlane::NONE) {
|
||||||
m_sketchGrid->paintGL(m_highlightedPlane.value(), m_shaderProgram, m_colorLoc);
|
m_sketchGrid->paintGL(static_cast<SketchGrid::SketchPlane>(m_highlightedPlane), m_shaderProgram, m_colorLoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_currentPlane) {
|
if (m_currentPlane != SketchPlane::NONE) {
|
||||||
m_sketchGrid->paintGL(m_currentPlane.value(), m_shaderProgram, m_colorLoc);
|
m_sketchGrid->paintGL(static_cast<SketchGrid::SketchPlane>(m_currentPlane), m_shaderProgram, m_colorLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_isSelectingPlane) {
|
if (m_isSelectingPlane) {
|
||||||
@@ -211,8 +208,8 @@ void ViewportWidget::paintGL()
|
|||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
if (m_currentPlane) {
|
if (m_currentPlane != SketchPlane::NONE) {
|
||||||
m_sketchGrid->paintAxisLabels(painter, m_currentPlane.value(), model, projection);
|
m_sketchGrid->paintAxisLabels(painter, static_cast<SketchGrid::SketchPlane>(m_currentPlane), model, projection);
|
||||||
}
|
}
|
||||||
m_featureBrowser->paint(painter, width(), height());
|
m_featureBrowser->paint(painter, width(), height());
|
||||||
m_viewCube->paint2D(painter, width(), height());
|
m_viewCube->paint2D(painter, width(), height());
|
||||||
@@ -239,10 +236,8 @@ void ViewportWidget::mousePressEvent(QMouseEvent *event)
|
|||||||
m_camera->mousePressEvent(event);
|
m_camera->mousePressEvent(event);
|
||||||
|
|
||||||
if (event->button() == Qt::MiddleButton && !(QApplication::keyboardModifiers() & Qt::ShiftModifier)) {
|
if (event->button() == Qt::MiddleButton && !(QApplication::keyboardModifiers() & Qt::ShiftModifier)) {
|
||||||
if (m_currentPlane) {
|
m_camera->startRotation(unproject(event->pos(), m_currentPlane));
|
||||||
m_camera->startRotation(unproject(event->pos(), m_currentPlane.value()));
|
update();
|
||||||
update();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
@@ -253,10 +248,10 @@ void ViewportWidget::mousePressEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_isSelectingPlane) {
|
if (m_isSelectingPlane) {
|
||||||
if (m_highlightedPlane) {
|
if (m_highlightedPlane != SketchPlane::NONE) {
|
||||||
emit planeSelected(m_highlightedPlane.value());
|
emit planeSelected(m_highlightedPlane);
|
||||||
m_isSelectingPlane = false;
|
m_isSelectingPlane = false;
|
||||||
m_highlightedPlane.reset();
|
m_highlightedPlane = SketchPlane::NONE;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -276,17 +271,8 @@ void ViewportWidget::mouseMoveEvent(QMouseEvent *event)
|
|||||||
m_currentMousePos = event->pos();
|
m_currentMousePos = event->pos();
|
||||||
|
|
||||||
if (m_isSelectingPlane) {
|
if (m_isSelectingPlane) {
|
||||||
auto newHighlight = checkPlaneSelection(m_currentMousePos);
|
SketchPlane newHighlight = checkPlaneSelection(m_currentMousePos);
|
||||||
bool needsUpdate = newHighlight.has_value() != m_highlightedPlane.has_value();
|
if (newHighlight != m_highlightedPlane) {
|
||||||
if (!needsUpdate && newHighlight) {
|
|
||||||
// Very basic check, assumes planes are one of the 3 cardinal ones
|
|
||||||
// and checkPlaneSelection returns them consistently.
|
|
||||||
if (!newHighlight->Direction().IsEqual(m_highlightedPlane->Direction(), 1e-9)) {
|
|
||||||
needsUpdate = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (needsUpdate) {
|
|
||||||
m_highlightedPlane = newHighlight;
|
m_highlightedPlane = newHighlight;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@@ -306,10 +292,8 @@ void ViewportWidget::mouseMoveEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
void ViewportWidget::wheelEvent(QWheelEvent *event)
|
void ViewportWidget::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
if (m_currentPlane) {
|
QVector3D worldPos = unproject(event->position().toPoint(), m_currentPlane);
|
||||||
QVector3D worldPos = unproject(event->position().toPoint(), m_currentPlane.value());
|
m_camera->wheelEvent(event, worldPos);
|
||||||
m_camera->wheelEvent(event, worldPos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewportWidget::keyPressEvent(QKeyEvent *event)
|
void ViewportWidget::keyPressEvent(QKeyEvent *event)
|
||||||
@@ -322,8 +306,8 @@ void ViewportWidget::keyPressEvent(QKeyEvent *event)
|
|||||||
if (event->key() == Qt::Key_Escape) {
|
if (event->key() == Qt::Key_Escape) {
|
||||||
if (m_isSelectingPlane) {
|
if (m_isSelectingPlane) {
|
||||||
m_isSelectingPlane = false;
|
m_isSelectingPlane = false;
|
||||||
m_highlightedPlane.reset();
|
m_highlightedPlane = SketchPlane::NONE;
|
||||||
m_currentPlane = gp_Ax2(gp::Origin(), gp::DZ());
|
m_currentPlane = SketchPlane::XY;
|
||||||
update();
|
update();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -388,19 +372,19 @@ bool ViewportWidget::focusNextPrevChild(bool next)
|
|||||||
return QOpenGLWidget::focusNextPrevChild(next);
|
return QOpenGLWidget::focusNextPrevChild(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewportWidget::onSketchModeStarted(const gp_Ax2& plane)
|
void ViewportWidget::onSketchModeStarted(SketchPlane plane)
|
||||||
{
|
{
|
||||||
m_currentPlane = plane;
|
m_currentPlane = plane;
|
||||||
|
|
||||||
m_camera->saveState();
|
m_camera->saveState();
|
||||||
m_camera->animateToPlaneView(plane);
|
m_camera->animateToPlaneView(static_cast<int>(plane));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewportWidget::onPlaneSelectionModeStarted()
|
void ViewportWidget::onPlaneSelectionModeStarted()
|
||||||
{
|
{
|
||||||
m_isSelectingPlane = true;
|
m_isSelectingPlane = true;
|
||||||
m_highlightedPlane.reset();
|
m_highlightedPlane = SketchPlane::NONE;
|
||||||
m_currentPlane.reset();
|
m_currentPlane = SketchPlane::NONE;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,7 +396,7 @@ void ViewportWidget::onSketchModeEnded()
|
|||||||
void ViewportWidget::onRestoreStateAnimationFinished()
|
void ViewportWidget::onRestoreStateAnimationFinished()
|
||||||
{
|
{
|
||||||
// Return to showing the base XY grid when not in a sketch
|
// Return to showing the base XY grid when not in a sketch
|
||||||
m_currentPlane = gp_Ax2(gp::Origin(), gp::DZ());
|
m_currentPlane = SketchPlane::XY;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,7 +468,7 @@ void ViewportWidget::onActiveToolChanged(int tool)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector3D ViewportWidget::unproject(const QPoint& screenPos, const gp_Ax2& plane)
|
QVector3D ViewportWidget::unproject(const QPoint& screenPos, SketchPlane plane)
|
||||||
{
|
{
|
||||||
QMatrix4x4 model = m_camera->modelViewMatrix();
|
QMatrix4x4 model = m_camera->modelViewMatrix();
|
||||||
|
|
||||||
@@ -513,13 +497,17 @@ QVector3D ViewportWidget::unproject(const QPoint& screenPos, const gp_Ax2& plane
|
|||||||
QVector3D rayOrigin(nearPoint_world);
|
QVector3D rayOrigin(nearPoint_world);
|
||||||
QVector3D rayDir = (QVector3D(farPoint_world) - rayOrigin).normalized();
|
QVector3D rayDir = (QVector3D(farPoint_world) - rayOrigin).normalized();
|
||||||
|
|
||||||
const auto& planeNormalDir = plane.Direction();
|
QVector3D planeNormal;
|
||||||
QVector3D planeNormal(planeNormalDir.X(), planeNormalDir.Y(), planeNormalDir.Z());
|
switch (plane) {
|
||||||
|
case SketchPlane::XY: planeNormal = QVector3D(0, 1, 0); break;
|
||||||
|
case SketchPlane::XZ: planeNormal = QVector3D(0, 0, 1); break;
|
||||||
|
case SketchPlane::YZ: planeNormal = QVector3D(1, 0, 0); break;
|
||||||
|
case SketchPlane::NONE: return QVector3D();
|
||||||
|
}
|
||||||
|
|
||||||
float denom = QVector3D::dotProduct(planeNormal, rayDir);
|
float denom = QVector3D::dotProduct(planeNormal, rayDir);
|
||||||
if (qAbs(denom) > 1e-6) {
|
if (qAbs(denom) > 1e-6) {
|
||||||
const auto& planeOriginPnt = plane.Location();
|
QVector3D p0(0,0,0);
|
||||||
QVector3D p0(planeOriginPnt.X(), planeOriginPnt.Y(), planeOriginPnt.Z());
|
|
||||||
float t = QVector3D::dotProduct(p0 - rayOrigin, planeNormal) / denom;
|
float t = QVector3D::dotProduct(p0 - rayOrigin, planeNormal) / denom;
|
||||||
return rayOrigin + t * rayDir;
|
return rayOrigin + t * rayDir;
|
||||||
}
|
}
|
||||||
@@ -553,11 +541,20 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch)
|
|||||||
|
|
||||||
const int numSegments = 64;
|
const int numSegments = 64;
|
||||||
QVector3D u_axis, v_axis;
|
QVector3D u_axis, v_axis;
|
||||||
const auto& plane = sketch->plane();
|
switch (sketch->plane()) {
|
||||||
const auto& xDir = plane.XDirection();
|
case SketchFeature::SketchPlane::XY:
|
||||||
const auto& yDir = plane.YDirection();
|
u_axis = QVector3D(1, 0, 0);
|
||||||
u_axis = QVector3D(xDir.X(), xDir.Y(), xDir.Z());
|
v_axis = QVector3D(0, 0, 1);
|
||||||
v_axis = QVector3D(yDir.X(), yDir.Y(), yDir.Z());
|
break;
|
||||||
|
case SketchFeature::SketchPlane::XZ:
|
||||||
|
u_axis = QVector3D(1, 0, 0);
|
||||||
|
v_axis = QVector3D(0, 1, 0);
|
||||||
|
break;
|
||||||
|
case SketchFeature::SketchPlane::YZ:
|
||||||
|
u_axis = QVector3D(0, 1, 0);
|
||||||
|
v_axis = QVector3D(0, 0, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < numSegments; ++i) {
|
for (int i = 0; i < numSegments; ++i) {
|
||||||
double angle1 = 2.0 * M_PI * double(i) / double(numSegments);
|
double angle1 = 2.0 * M_PI * double(i) / double(numSegments);
|
||||||
@@ -571,32 +568,34 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch)
|
|||||||
}
|
}
|
||||||
} else if (obj->type() == SketchObject::ObjectType::Rectangle) {
|
} else if (obj->type() == SketchObject::ObjectType::Rectangle) {
|
||||||
auto rect = static_cast<const SketchRectangle*>(obj);
|
auto rect = static_cast<const SketchRectangle*>(obj);
|
||||||
const auto& plane = sketch->plane();
|
const auto& p1 = rect->corner1();
|
||||||
const auto& p1_3d = rect->corner1();
|
const auto& p3 = rect->corner2();
|
||||||
const auto& p3_3d = rect->corner2();
|
|
||||||
|
|
||||||
gp_Pnt2d p1_2d(gp_Vec(plane.Location(), p1_3d).Dot(plane.XDirection()), gp_Vec(plane.Location(), p1_3d).Dot(plane.YDirection()));
|
gp_Pnt p2, p4;
|
||||||
gp_Pnt2d p3_2d(gp_Vec(plane.Location(), p3_3d).Dot(plane.XDirection()), gp_Vec(plane.Location(), p3_3d).Dot(plane.YDirection()));
|
if (sketch->plane() == SketchFeature::SketchPlane::XY) {
|
||||||
|
p2.SetCoord(p3.X(), p1.Y(), p1.Z());
|
||||||
|
p4.SetCoord(p1.X(), p1.Y(), p3.Z());
|
||||||
|
} else if (sketch->plane() == SketchFeature::SketchPlane::XZ) {
|
||||||
|
p2.SetCoord(p3.X(), p1.Y(), p1.Z());
|
||||||
|
p4.SetCoord(p1.X(), p3.Y(), p1.Z());
|
||||||
|
} else if (sketch->plane() == SketchFeature::SketchPlane::YZ) {
|
||||||
|
p2.SetCoord(p1.X(), p3.Y(), p1.Z());
|
||||||
|
p4.SetCoord(p1.X(), p1.Y(), p3.Z());
|
||||||
|
}
|
||||||
|
|
||||||
gp_Pnt2d p2_2d(p3_2d.X(), p1_2d.Y());
|
lineVertices << p1.X() << p1.Y() << p1.Z();
|
||||||
gp_Pnt2d p4_2d(p1_2d.X(), p3_2d.Y());
|
lineVertices << p2.X() << p2.Y() << p2.Z();
|
||||||
|
lineVertices << p2.X() << p2.Y() << p2.Z();
|
||||||
|
lineVertices << p3.X() << p3.Y() << p3.Z();
|
||||||
|
lineVertices << p3.X() << p3.Y() << p3.Z();
|
||||||
|
lineVertices << p4.X() << p4.Y() << p4.Z();
|
||||||
|
lineVertices << p4.X() << p4.Y() << p4.Z();
|
||||||
|
lineVertices << p1.X() << p1.Y() << p1.Z();
|
||||||
|
|
||||||
gp_Pnt p2_3d = ElCLib::To3d(plane, p2_2d);
|
vertexCounts[p1] += 2;
|
||||||
gp_Pnt p4_3d = ElCLib::To3d(plane, p4_2d);
|
vertexCounts[p2] += 2;
|
||||||
|
vertexCounts[p3] += 2;
|
||||||
lineVertices << p1_3d.X() << p1_3d.Y() << p1_3d.Z();
|
vertexCounts[p4] += 2;
|
||||||
lineVertices << p2_3d.X() << p2_3d.Y() << p2_3d.Z();
|
|
||||||
lineVertices << p2_3d.X() << p2_3d.Y() << p2_3d.Z();
|
|
||||||
lineVertices << p3_3d.X() << p3_3d.Y() << p3_3d.Z();
|
|
||||||
lineVertices << p3_3d.X() << p3_3d.Y() << p3_3d.Z();
|
|
||||||
lineVertices << p4_3d.X() << p4_3d.Y() << p4_3d.Z();
|
|
||||||
lineVertices << p4_3d.X() << p4_3d.Y() << p4_3d.Z();
|
|
||||||
lineVertices << p1_3d.X() << p1_3d.Y() << p1_3d.Z();
|
|
||||||
|
|
||||||
vertexCounts[p1_3d] += 2;
|
|
||||||
vertexCounts[p2_3d] += 2;
|
|
||||||
vertexCounts[p3_3d] += 2;
|
|
||||||
vertexCounts[p4_3d] += 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -605,6 +604,9 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch)
|
|||||||
|
|
||||||
if (!lineVertices.isEmpty()) {
|
if (!lineVertices.isEmpty()) {
|
||||||
m_vbo.allocate(lineVertices.constData(), lineVertices.size() * sizeof(GLfloat));
|
m_vbo.allocate(lineVertices.constData(), lineVertices.size() * sizeof(GLfloat));
|
||||||
|
m_shaderProgram->enableAttributeArray(0);
|
||||||
|
m_shaderProgram->setAttributeBuffer(0, GL_FLOAT, 0, 3, 0);
|
||||||
|
m_shaderProgram->disableAttributeArray(1);
|
||||||
glDrawArrays(GL_LINES, 0, lineVertices.size() / 3);
|
glDrawArrays(GL_LINES, 0, lineVertices.size() / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,13 +662,88 @@ void ViewportWidget::drawSketch(const SketchFeature* sketch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw faces
|
||||||
|
if (!sketch->shape().IsNull()) {
|
||||||
|
glDisable(GL_CULL_FACE);
|
||||||
|
BRepMesh_IncrementalMesh(sketch->shape(), 0.1, Standard_False, 0.5, Standard_True); // Linear deflection, compute normals
|
||||||
|
|
||||||
|
QVector<GLfloat> faceData;
|
||||||
|
TopExp_Explorer explorer(sketch->shape(), TopAbs_FACE);
|
||||||
|
for (; explorer.More(); explorer.Next()) {
|
||||||
|
TopoDS_Face face = TopoDS::Face(explorer.Current());
|
||||||
|
TopLoc_Location location;
|
||||||
|
Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation(face, location);
|
||||||
|
|
||||||
|
if (!triangulation.IsNull()) {
|
||||||
|
gp_Trsf locTrsf = location.Transformation();
|
||||||
|
|
||||||
|
if (triangulation->HasNormals()) {
|
||||||
|
for (int i = 1; i <= triangulation->NbTriangles(); ++i) {
|
||||||
|
const Poly_Triangle& triangle = triangulation->Triangle(i);
|
||||||
|
for (int j = 1; j <= 3; ++j) {
|
||||||
|
int nodeIdx = triangle.Value(j);
|
||||||
|
gp_Pnt p = triangulation->Node(nodeIdx).Transformed(location);
|
||||||
|
gp_Dir n = triangulation->Normal(nodeIdx);
|
||||||
|
n.Transform(locTrsf);
|
||||||
|
|
||||||
|
if (face.Orientation() == TopAbs_REVERSED) {
|
||||||
|
n.Reverse();
|
||||||
|
}
|
||||||
|
faceData << p.X() << p.Y() << p.Z();
|
||||||
|
faceData << n.X() << n.Y() << n.Z();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = 1; i <= triangulation->NbTriangles(); ++i) {
|
||||||
|
const Poly_Triangle& triangle = triangulation->Triangle(i);
|
||||||
|
gp_Pnt p1 = triangulation->Node(triangle.Value(1)).Transformed(location);
|
||||||
|
gp_Pnt p2 = triangulation->Node(triangle.Value(2)).Transformed(location);
|
||||||
|
gp_Pnt p3 = triangulation->Node(triangle.Value(3)).Transformed(location);
|
||||||
|
|
||||||
|
QVector3D v1(p1.X(), p1.Y(), p1.Z());
|
||||||
|
QVector3D v2(p2.X(), p2.Y(), p2.Z());
|
||||||
|
QVector3D v3(p3.X(), p3.Y(), p3.Z());
|
||||||
|
QVector3D faceNormal = QVector3D::crossProduct(v2 - v1, v3 - v1).normalized();
|
||||||
|
if (face.Orientation() == TopAbs_REVERSED) {
|
||||||
|
faceNormal = -faceNormal;
|
||||||
|
}
|
||||||
|
faceData << p1.X() << p1.Y() << p1.Z() << faceNormal.x() << faceNormal.y() << faceNormal.z();
|
||||||
|
faceData << p2.X() << p2.Y() << p2.Z() << faceNormal.x() << faceNormal.y() << faceNormal.z();
|
||||||
|
faceData << p3.X() << p3.Y() << p3.Z() << faceNormal.x() << faceNormal.y() << faceNormal.z();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!faceData.isEmpty()) {
|
||||||
|
m_litShaderProgram->bind();
|
||||||
|
m_litShaderProgram->setUniformValue(m_litProjMatrixLoc, projection);
|
||||||
|
m_litShaderProgram->setUniformValue(m_litMvMatrixLoc, m_camera->modelViewMatrix());
|
||||||
|
m_litShaderProgram->setUniformValue(m_litNormalMatrixLoc, m_camera->modelViewMatrix().normalMatrix());
|
||||||
|
|
||||||
|
m_vbo.bind();
|
||||||
|
m_vbo.allocate(faceData.constData(), faceData.size() * sizeof(GLfloat));
|
||||||
|
|
||||||
|
m_litShaderProgram->enableAttributeArray(0);
|
||||||
|
m_litShaderProgram->setAttributeBuffer(0, GL_FLOAT, 0, 3, 6 * sizeof(GLfloat));
|
||||||
|
m_litShaderProgram->enableAttributeArray(1);
|
||||||
|
m_litShaderProgram->setAttributeBuffer(1, GL_FLOAT, 3 * sizeof(GLfloat), 3, 6 * sizeof(GLfloat));
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, faceData.size() / 6);
|
||||||
|
m_litShaderProgram->disableAttributeArray(1);
|
||||||
|
m_shaderProgram->bind(); // rebind simple shader for subsequent draws
|
||||||
|
m_shaderProgram->setAttributeBuffer(0, GL_FLOAT, 0, 3, 0);
|
||||||
|
}
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
}
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewportWidget::initShaders()
|
void ViewportWidget::initShaders()
|
||||||
{
|
{
|
||||||
|
// Simple shader for lines and grids
|
||||||
m_shaderProgram = new QOpenGLShaderProgram(this);
|
m_shaderProgram = new QOpenGLShaderProgram(this);
|
||||||
|
|
||||||
if (!m_shaderProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shaders/simple.vert")) {
|
if (!m_shaderProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shaders/simple.vert")) {
|
||||||
qCritical() << "Vertex shader compilation failed:" << m_shaderProgram->log();
|
qCritical() << "Vertex shader compilation failed:" << m_shaderProgram->log();
|
||||||
return;
|
return;
|
||||||
@@ -679,10 +756,27 @@ void ViewportWidget::initShaders()
|
|||||||
qCritical() << "Shader program linking failed:" << m_shaderProgram->log();
|
qCritical() << "Shader program linking failed:" << m_shaderProgram->log();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_projMatrixLoc = m_shaderProgram->uniformLocation("projectionMatrix");
|
m_projMatrixLoc = m_shaderProgram->uniformLocation("projectionMatrix");
|
||||||
m_mvMatrixLoc = m_shaderProgram->uniformLocation("modelViewMatrix");
|
m_mvMatrixLoc = m_shaderProgram->uniformLocation("modelViewMatrix");
|
||||||
m_colorLoc = m_shaderProgram->uniformLocation("objectColor");
|
m_colorLoc = m_shaderProgram->uniformLocation("objectColor");
|
||||||
|
|
||||||
|
// Lit shader for faces
|
||||||
|
m_litShaderProgram = new QOpenGLShaderProgram(this);
|
||||||
|
if (!m_litShaderProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shaders/lit.vert")) {
|
||||||
|
qCritical() << "Lit vertex shader compilation failed:" << m_litShaderProgram->log();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!m_litShaderProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/shaders/lit.frag")) {
|
||||||
|
qCritical() << "Lit fragment shader compilation failed:" << m_litShaderProgram->log();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!m_litShaderProgram->link()) {
|
||||||
|
qCritical() << "Lit shader program linking failed:" << m_litShaderProgram->log();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_litProjMatrixLoc = m_litShaderProgram->uniformLocation("projectionMatrix");
|
||||||
|
m_litMvMatrixLoc = m_litShaderProgram->uniformLocation("modelViewMatrix");
|
||||||
|
m_litNormalMatrixLoc = m_litShaderProgram->uniformLocation("normalMatrix");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewportWidget::drawSelectionPlanes()
|
void ViewportWidget::drawSelectionPlanes()
|
||||||
@@ -697,6 +791,9 @@ void ViewportWidget::drawSelectionPlanes()
|
|||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
m_vbo.bind();
|
m_vbo.bind();
|
||||||
|
m_shaderProgram->enableAttributeArray(0);
|
||||||
|
m_shaderProgram->setAttributeBuffer(0, GL_FLOAT, 0, 3, 0);
|
||||||
|
m_shaderProgram->disableAttributeArray(1);
|
||||||
QVector<GLfloat> vertices;
|
QVector<GLfloat> vertices;
|
||||||
|
|
||||||
auto drawPlane = [&](const QVector<GLfloat>& quadVerts, bool highlighted) {
|
auto drawPlane = [&](const QVector<GLfloat>& quadVerts, bool highlighted) {
|
||||||
@@ -713,58 +810,54 @@ void ViewportWidget::drawSelectionPlanes()
|
|||||||
};
|
};
|
||||||
|
|
||||||
// XY Plane (Top)
|
// XY Plane (Top)
|
||||||
QVector<GLfloat> xyQuad = { planeOffset, -planeOffset, 0, planeOffset + planeSize, -planeOffset, 0,
|
QVector<GLfloat> xyQuad = { planeOffset, 0, planeOffset, planeOffset + planeSize, 0, planeOffset,
|
||||||
planeOffset + planeSize, -planeOffset - planeSize, 0, planeOffset, -planeOffset - planeSize, 0 };
|
planeOffset + planeSize, 0, planeOffset + planeSize, planeOffset, 0, planeOffset + planeSize };
|
||||||
drawPlane(xyQuad, m_highlightedPlane && m_highlightedPlane->Direction().IsEqual(gp::DZ(), 1e-9));
|
drawPlane(xyQuad, m_highlightedPlane == SketchPlane::XY);
|
||||||
|
|
||||||
// XZ Plane (Front)
|
// XZ Plane (Front)
|
||||||
QVector<GLfloat> xzQuad = { planeOffset, 0, planeOffset, planeOffset + planeSize, 0, planeOffset,
|
QVector<GLfloat> xzQuad = { planeOffset, planeOffset, 0, planeOffset + planeSize, planeOffset, 0,
|
||||||
planeOffset + planeSize, 0, planeOffset + planeSize, planeOffset, 0, planeOffset + planeSize };
|
planeOffset + planeSize, planeOffset + planeSize, 0, planeOffset, planeOffset + planeSize, 0 };
|
||||||
drawPlane(xzQuad, m_highlightedPlane && m_highlightedPlane->Direction().IsEqual(gp::DY(), 1e-9));
|
drawPlane(xzQuad, m_highlightedPlane == SketchPlane::XZ);
|
||||||
|
|
||||||
// YZ Plane (Right)
|
// YZ Plane (Right)
|
||||||
QVector<GLfloat> yzQuad = { 0, -planeOffset, planeOffset, 0, -planeOffset, planeOffset + planeSize,
|
QVector<GLfloat> yzQuad = { 0, planeOffset, planeOffset, 0, planeOffset + planeSize, planeOffset,
|
||||||
0, -planeOffset - planeSize, planeOffset + planeSize, 0, -planeOffset - planeSize, planeOffset };
|
0, planeOffset + planeSize, planeOffset + planeSize, 0, planeOffset, planeOffset + planeSize };
|
||||||
drawPlane(yzQuad, m_highlightedPlane && m_highlightedPlane->Direction().IsEqual(gp::DX(), 1e-9));
|
drawPlane(yzQuad, m_highlightedPlane == SketchPlane::YZ);
|
||||||
|
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<gp_Ax2> ViewportWidget::checkPlaneSelection(const QPoint& screenPos)
|
ViewportWidget::SketchPlane ViewportWidget::checkPlaneSelection(const QPoint& screenPos)
|
||||||
{
|
{
|
||||||
const float planeSize = 5.0f;
|
const float planeSize = 5.0f;
|
||||||
const float planeOffset = 1.0f;
|
const float planeOffset = 1.0f;
|
||||||
|
|
||||||
gp_Ax2 yzPlane(gp_Pnt(0, 0, 0), gp::DX());
|
|
||||||
gp_Ax2 xzPlane(gp_Pnt(0, 0, 0), gp::DY());
|
|
||||||
gp_Ax2 xyPlane(gp_Pnt(0, 0, 0), gp::DZ());
|
|
||||||
|
|
||||||
QVector3D intersection;
|
QVector3D intersection;
|
||||||
|
|
||||||
// Check front to back to handle overlaps
|
// Check front to back to handle overlaps
|
||||||
// YZ plane (Right)
|
// YZ plane (Right)
|
||||||
intersection = unproject(screenPos, yzPlane);
|
intersection = unproject(screenPos, SketchPlane::YZ);
|
||||||
if (intersection.y() >= -planeOffset - planeSize && intersection.y() <= -planeOffset &&
|
if (intersection.y() >= planeOffset && intersection.y() <= planeOffset + planeSize &&
|
||||||
intersection.z() >= planeOffset && intersection.z() <= planeOffset + planeSize) {
|
intersection.z() >= planeOffset && intersection.z() <= planeOffset + planeSize) {
|
||||||
return gp_Ax2(gp_Pnt(0, -planeOffset, planeOffset), gp::DX());
|
return SketchPlane::YZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XZ plane (Front)
|
// XZ plane (Front)
|
||||||
intersection = unproject(screenPos, xzPlane);
|
intersection = unproject(screenPos, SketchPlane::XZ);
|
||||||
if (intersection.x() >= planeOffset && intersection.x() <= planeOffset + planeSize &&
|
if (intersection.x() >= planeOffset && intersection.x() <= planeOffset + planeSize &&
|
||||||
intersection.z() >= planeOffset && intersection.z() <= planeOffset + planeSize) {
|
intersection.y() >= planeOffset && intersection.y() <= planeOffset + planeSize) {
|
||||||
return gp_Ax2(gp_Pnt(planeOffset, 0, planeOffset), gp::DY());
|
return SketchPlane::XZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XY plane (Top)
|
// XY plane (Top)
|
||||||
intersection = unproject(screenPos, xyPlane);
|
intersection = unproject(screenPos, SketchPlane::XY);
|
||||||
if (intersection.x() >= planeOffset && intersection.x() <= planeOffset + planeSize &&
|
if (intersection.x() >= planeOffset && intersection.x() <= planeOffset + planeSize &&
|
||||||
intersection.y() >= -planeOffset - planeSize && intersection.y() <= -planeOffset) {
|
intersection.z() >= planeOffset && intersection.z() <= planeOffset + planeSize) {
|
||||||
return gp_Ax2(gp_Pnt(planeOffset, -planeOffset, 0), gp::DZ());
|
return SketchPlane::XY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::nullopt;
|
return SketchPlane::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+20
-16
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#ifndef VIEWPORTWIDGET_H
|
#ifndef VIEWPORTWIDGET_H
|
||||||
#define VIEWPORTWIDGET_H
|
#define VIEWPORTWIDGET_H
|
||||||
|
|
||||||
@@ -15,8 +8,6 @@
|
|||||||
#include <QVector3D>
|
#include <QVector3D>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
#include <gp_Pnt.hxx>
|
#include <gp_Pnt.hxx>
|
||||||
#include <gp_Ax2.hxx>
|
|
||||||
#include <optional>
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <QOpenGLVertexArrayObject>
|
#include <QOpenGLVertexArrayObject>
|
||||||
@@ -37,19 +28,26 @@ class ViewportWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum class SketchPlane {
|
||||||
|
NONE,
|
||||||
|
XY,
|
||||||
|
XZ,
|
||||||
|
YZ
|
||||||
|
};
|
||||||
|
|
||||||
explicit ViewportWidget(QWidget *parent = nullptr);
|
explicit ViewportWidget(QWidget *parent = nullptr);
|
||||||
~ViewportWidget();
|
~ViewportWidget();
|
||||||
|
|
||||||
void setDocument(Document* document);
|
void setDocument(Document* document);
|
||||||
|
|
||||||
QVector3D project(const QVector3D& worldCoord, const QMatrix4x4& modelView, const QMatrix4x4& projection, const QRect& viewport);
|
QVector3D project(const QVector3D& worldCoord, const QMatrix4x4& modelView, const QMatrix4x4& projection, const QRect& viewport);
|
||||||
QVector3D unproject(const QPoint& screenPos, const gp_Ax2& plane);
|
QVector3D unproject(const QPoint& screenPos, SketchPlane plane);
|
||||||
QOpenGLShaderProgram* shaderProgram() { return m_shaderProgram; }
|
QOpenGLShaderProgram* shaderProgram() { return m_shaderProgram; }
|
||||||
QOpenGLBuffer& vbo() { return m_vbo; }
|
QOpenGLBuffer& vbo() { return m_vbo; }
|
||||||
int colorLoc() const { return m_colorLoc; }
|
int colorLoc() const { return m_colorLoc; }
|
||||||
Camera* camera() const { return m_camera; }
|
Camera* camera() const { return m_camera; }
|
||||||
Document* document() const { return m_document; }
|
Document* document() const { return m_document; }
|
||||||
std::optional<gp_Ax2> currentPlane() const { return m_currentPlane; }
|
SketchPlane currentPlane() const { return m_currentPlane; }
|
||||||
const QPoint& currentMousePos() const { return m_currentMousePos; }
|
const QPoint& currentMousePos() const { return m_currentMousePos; }
|
||||||
bool isSnappingOrigin() const;
|
bool isSnappingOrigin() const;
|
||||||
bool isSnappingVertex() const;
|
bool isSnappingVertex() const;
|
||||||
@@ -64,7 +62,7 @@ public:
|
|||||||
void deactivateActiveTool();
|
void deactivateActiveTool();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onSketchModeStarted(const gp_Ax2& plane);
|
void onSketchModeStarted(SketchPlane plane);
|
||||||
void onSketchModeEnded();
|
void onSketchModeEnded();
|
||||||
void onPlaneSelectionModeStarted();
|
void onPlaneSelectionModeStarted();
|
||||||
void onActiveToolChanged(int tool);
|
void onActiveToolChanged(int tool);
|
||||||
@@ -73,7 +71,7 @@ signals:
|
|||||||
void lineAdded(const gp_Pnt& start, const gp_Pnt& end);
|
void lineAdded(const gp_Pnt& start, const gp_Pnt& end);
|
||||||
void rectangleAdded(const gp_Pnt& corner1, const gp_Pnt& corner2);
|
void rectangleAdded(const gp_Pnt& corner1, const gp_Pnt& corner2);
|
||||||
void circleAdded(const gp_Pnt& center, double radius);
|
void circleAdded(const gp_Pnt& center, double radius);
|
||||||
void planeSelected(const gp_Ax2& plane);
|
void planeSelected(SketchPlane plane);
|
||||||
void toolDeactivated();
|
void toolDeactivated();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@@ -95,10 +93,11 @@ private:
|
|||||||
void initShaders();
|
void initShaders();
|
||||||
void drawSketch(const SketchFeature* sketch);
|
void drawSketch(const SketchFeature* sketch);
|
||||||
void drawSelectionPlanes();
|
void drawSelectionPlanes();
|
||||||
std::optional<gp_Ax2> checkPlaneSelection(const QPoint& screenPos);
|
ViewportWidget::SketchPlane checkPlaneSelection(const QPoint& screenPos);
|
||||||
|
|
||||||
QMatrix4x4 projection;
|
QMatrix4x4 projection;
|
||||||
QOpenGLShaderProgram* m_shaderProgram = nullptr;
|
QOpenGLShaderProgram* m_shaderProgram = nullptr;
|
||||||
|
QOpenGLShaderProgram* m_litShaderProgram = nullptr;
|
||||||
QOpenGLVertexArrayObject m_vao;
|
QOpenGLVertexArrayObject m_vao;
|
||||||
QOpenGLBuffer m_vbo;
|
QOpenGLBuffer m_vbo;
|
||||||
|
|
||||||
@@ -106,15 +105,20 @@ private:
|
|||||||
int m_projMatrixLoc = -1;
|
int m_projMatrixLoc = -1;
|
||||||
int m_mvMatrixLoc = -1;
|
int m_mvMatrixLoc = -1;
|
||||||
int m_colorLoc = -1;
|
int m_colorLoc = -1;
|
||||||
|
|
||||||
|
// Lit shader uniform locations
|
||||||
|
int m_litProjMatrixLoc = -1;
|
||||||
|
int m_litMvMatrixLoc = -1;
|
||||||
|
int m_litNormalMatrixLoc = -1;
|
||||||
Camera* m_camera = nullptr;
|
Camera* m_camera = nullptr;
|
||||||
ViewCube* m_viewCube;
|
ViewCube* m_viewCube;
|
||||||
SketchGrid* m_sketchGrid = nullptr;
|
SketchGrid* m_sketchGrid = nullptr;
|
||||||
FeatureBrowser* m_featureBrowser = nullptr;
|
FeatureBrowser* m_featureBrowser = nullptr;
|
||||||
Document* m_document = nullptr;
|
Document* m_document = nullptr;
|
||||||
std::optional<gp_Ax2> m_currentPlane;
|
SketchPlane m_currentPlane = SketchPlane::NONE;
|
||||||
|
|
||||||
bool m_isSelectingPlane = false;
|
bool m_isSelectingPlane = false;
|
||||||
std::optional<gp_Ax2> m_highlightedPlane;
|
SketchPlane m_highlightedPlane = SketchPlane::NONE;
|
||||||
|
|
||||||
int m_activeTool = 0;
|
int m_activeTool = 0;
|
||||||
SketchTool* m_activeSketchTool = nullptr;
|
SketchTool* m_activeSketchTool = nullptr;
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
// Unnamed CAD Software
|
|
||||||
//
|
|
||||||
// License: GPLv3 (or later)
|
|
||||||
// Language: C++17
|
|
||||||
// Notes:
|
|
||||||
// - use a right-handed, Z-up coordinate system to match Open CASCADE
|
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "ApplicationController.h"
|
#include "ApplicationController.h"
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#version 330 core
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
in vec3 FragPos;
|
||||||
|
in vec3 Normal;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 viewPos = vec3(0.0, 0.0, 0.0); // View position is origin in view space
|
||||||
|
vec3 lightPos = vec3(0.0, 10.0, 5.0); // Light position in view space
|
||||||
|
vec3 lightColor = vec3(1.0, 1.0, 1.0);
|
||||||
|
vec3 objectColor = vec3(0.5, 0.5, 1.0);
|
||||||
|
|
||||||
|
// Ambient
|
||||||
|
float ambientStrength = 0.3;
|
||||||
|
vec3 ambient = ambientStrength * lightColor;
|
||||||
|
|
||||||
|
// Diffuse
|
||||||
|
vec3 norm = normalize(Normal);
|
||||||
|
vec3 lightDir = normalize(lightPos - FragPos);
|
||||||
|
float diff = max(dot(norm, lightDir), 0.0);
|
||||||
|
vec3 diffuse = diff * lightColor;
|
||||||
|
|
||||||
|
// Specular
|
||||||
|
float specularStrength = 0.5;
|
||||||
|
vec3 viewDir = normalize(viewPos - FragPos);
|
||||||
|
vec3 reflectDir = reflect(-lightDir, norm);
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
||||||
|
vec3 specular = specularStrength * spec * lightColor;
|
||||||
|
|
||||||
|
vec3 result = (ambient + diffuse + specular) * objectColor;
|
||||||
|
FragColor = vec4(result, 1.0);
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#version 330 core
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
layout (location = 1) in vec3 aNormal;
|
||||||
|
|
||||||
|
out vec3 FragPos;
|
||||||
|
out vec3 Normal;
|
||||||
|
|
||||||
|
uniform mat4 modelViewMatrix;
|
||||||
|
uniform mat4 projectionMatrix;
|
||||||
|
uniform mat3 normalMatrix;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
FragPos = vec3(modelViewMatrix * vec4(aPos, 1.0));
|
||||||
|
Normal = normalMatrix * aNormal;
|
||||||
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(aPos, 1.0);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user