mirror of
https://github.com/leozide/leocad
synced 2025-01-30 20:34:56 +01:00
Added model measurements. Fixes #631.
This commit is contained in:
parent
d0404d9fbb
commit
140daced93
6 changed files with 93 additions and 51 deletions
|
@ -3177,7 +3177,7 @@ lcVector3 lcModel::GetSelectionOrModelCenter() const
|
|||
{
|
||||
lcVector3 Min(FLT_MAX, FLT_MAX, FLT_MAX), Max(-FLT_MAX, -FLT_MAX, -FLT_MAX);
|
||||
|
||||
if (GetPiecesBoundingBox(Min, Max))
|
||||
if (GetVisiblePiecesBoundingBox(Min, Max))
|
||||
Center = (Min + Max) / 2.0f;
|
||||
else
|
||||
Center = lcVector3(0.0f, 0.0f, 0.0f);
|
||||
|
@ -3253,7 +3253,25 @@ bool lcModel::GetSelectionCenter(lcVector3& Center) const
|
|||
return Selected;
|
||||
}
|
||||
|
||||
bool lcModel::GetPiecesBoundingBox(lcVector3& Min, lcVector3& Max) const
|
||||
lcBoundingBox lcModel::GetAllPiecesBoundingBox() const
|
||||
{
|
||||
lcBoundingBox Box;
|
||||
|
||||
if (!mPieces.IsEmpty())
|
||||
{
|
||||
Box.Min = lcVector3(FLT_MAX, FLT_MAX, FLT_MAX);
|
||||
Box.Max = lcVector3(-FLT_MAX, -FLT_MAX, -FLT_MAX);
|
||||
|
||||
for (lcPiece* Piece : mPieces)
|
||||
Piece->CompareBoundingBox(Box.Min, Box.Max);
|
||||
}
|
||||
else
|
||||
Box.Min = Box.Max = lcVector3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
return Box;
|
||||
}
|
||||
|
||||
bool lcModel::GetVisiblePiecesBoundingBox(lcVector3& Min, lcVector3& Max) const
|
||||
{
|
||||
bool Valid = false;
|
||||
Min = lcVector3(FLT_MAX, FLT_MAX, FLT_MAX);
|
||||
|
@ -4207,7 +4225,7 @@ void lcModel::LookAt(lcCamera* Camera)
|
|||
{
|
||||
lcVector3 Min(FLT_MAX, FLT_MAX, FLT_MAX), Max(-FLT_MAX, -FLT_MAX, -FLT_MAX);
|
||||
|
||||
if (GetPiecesBoundingBox(Min, Max))
|
||||
if (GetVisiblePiecesBoundingBox(Min, Max))
|
||||
Center = (Min + Max) / 2.0f;
|
||||
else
|
||||
Center = lcVector3(0.0f, 0.0f, 0.0f);
|
||||
|
@ -4276,6 +4294,7 @@ void lcModel::ShowPropertiesDialog()
|
|||
lcPropertiesDialogOptions Options;
|
||||
|
||||
Options.Properties = mProperties;
|
||||
Options.BoundingBox = GetAllPiecesBoundingBox();
|
||||
|
||||
GetPartsList(gDefaultColor, true, false, Options.PartsList);
|
||||
|
||||
|
|
|
@ -257,7 +257,8 @@ public:
|
|||
bool GetFocusPosition(lcVector3& Position) const;
|
||||
lcObject* GetFocusObject() const;
|
||||
bool GetSelectionCenter(lcVector3& Center) const;
|
||||
bool GetPiecesBoundingBox(lcVector3& Min, lcVector3& Max) const;
|
||||
lcBoundingBox GetAllPiecesBoundingBox() const;
|
||||
bool GetVisiblePiecesBoundingBox(lcVector3& Min, lcVector3& Max) const;
|
||||
std::vector<lcVector3> GetPiecesBoundingBoxPoints() const;
|
||||
void GetPartsList(int DefaultColorIndex, bool ScanSubModels, bool AddSubModels, lcPartsList& PartsList) const;
|
||||
void GetPartsListForStep(lcStep Step, int DefaultColorIndex, lcPartsList& PartsList) const;
|
||||
|
|
|
@ -632,7 +632,7 @@ lcVector3 lcView::GetCameraLightInsertPosition() const
|
|||
lcVector3 Min, Max;
|
||||
lcVector3 Center;
|
||||
|
||||
if (ActiveModel->GetPiecesBoundingBox(Min, Max))
|
||||
if (ActiveModel->GetVisiblePiecesBoundingBox(Min, Max))
|
||||
Center = (Min + Max) / 2.0f;
|
||||
else
|
||||
Center = lcVector3(0.0f, 0.0f, 0.0f);
|
||||
|
@ -1875,7 +1875,7 @@ void lcView::DrawGrid()
|
|||
int MinX, MaxX, MinY, MaxY;
|
||||
lcVector3 Min(FLT_MAX, FLT_MAX, FLT_MAX), Max(-FLT_MAX, -FLT_MAX, -FLT_MAX);
|
||||
|
||||
bool GridSizeValid = mModel->GetPiecesBoundingBox(Min, Max);
|
||||
bool GridSizeValid = mModel->GetVisiblePiecesBoundingBox(Min, Max);
|
||||
|
||||
if (mTrackTool == lcTrackTool::Insert)
|
||||
{
|
||||
|
|
|
@ -43,12 +43,20 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget* Parent, lcPropertiesDialogOpti
|
|||
|
||||
setWindowTitle(tr("%1 Properties").arg(mOptions->Properties.mFileName));
|
||||
|
||||
ui->descriptionEdit->setText(mOptions->Properties.mDescription);
|
||||
ui->authorEdit->setText(mOptions->Properties.mAuthor);
|
||||
ui->commentsEdit->setText(mOptions->Properties.mComments);
|
||||
ui->DescriptionEdit->setText(mOptions->Properties.mDescription);
|
||||
ui->AuthorEdit->setText(mOptions->Properties.mAuthor);
|
||||
ui->CommentsEdit->setText(mOptions->Properties.mComments);
|
||||
|
||||
const lcVector3 Dimensions = Options->BoundingBox.Max - Options->BoundingBox.Min;
|
||||
QString Format = tr("%1 x %2 x %3 cm\n%4 x %5 x %6 inches\n%7 x %8 x %9 LDU");
|
||||
QString Measurements = Format.arg(QString::number(Dimensions.x * 0.04, 'f', 2), QString::number(Dimensions.y * 0.04, 'f', 2), QString::number(Dimensions.z * 0.04, 'f', 2),
|
||||
QString::number(Dimensions.x / 64.0, 'f', 2), QString::number(Dimensions.y / 64.0, 'f', 2), QString::number(Dimensions.z / 64.0, 'f', 2),
|
||||
QString::number(Dimensions.x, 'f', 2), QString::number(Dimensions.y, 'f', 2), QString::number(Dimensions.z, 'f', 2));
|
||||
|
||||
ui->MeasurementsLabel->setText(Measurements);
|
||||
|
||||
const lcPartsList& PartsList = mOptions->PartsList;
|
||||
QStringList horizontalLabels;
|
||||
QStringList HorizontalLabels;
|
||||
|
||||
std::vector<bool> ColorsUsed(gColorList.size());
|
||||
|
||||
|
@ -57,34 +65,34 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget* Parent, lcPropertiesDialogOpti
|
|||
ColorsUsed[ColorIt.first] = true;
|
||||
|
||||
std::vector<int> ColorColumns(gColorList.size());
|
||||
int NumColors = 0;
|
||||
int ColorCount = 0;
|
||||
|
||||
horizontalLabels.append(tr("Part"));
|
||||
HorizontalLabels.append(tr("Part"));
|
||||
|
||||
for (size_t ColorIndex = 0; ColorIndex < gColorList.size(); ColorIndex++)
|
||||
{
|
||||
if (ColorsUsed[ColorIndex])
|
||||
{
|
||||
ColorColumns[ColorIndex] = NumColors++;
|
||||
horizontalLabels.append(gColorList[ColorIndex].Name);
|
||||
ColorColumns[ColorIndex] = ColorCount++;
|
||||
HorizontalLabels.append(gColorList[ColorIndex].Name);
|
||||
}
|
||||
}
|
||||
|
||||
horizontalLabels.append(tr("Total"));
|
||||
HorizontalLabels.append(tr("Total"));
|
||||
|
||||
QTableWidget *table = ui->partsTable;
|
||||
table->setColumnCount(NumColors + 2);
|
||||
table->setRowCount((int)PartsList.size() + 1);
|
||||
table->setHorizontalHeaderLabels(horizontalLabels);
|
||||
table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
QTableWidget* PartsTable = ui->PartsTable;
|
||||
PartsTable->setColumnCount(ColorCount + 2);
|
||||
PartsTable->setRowCount((int)PartsList.size() + 1);
|
||||
PartsTable->setHorizontalHeaderLabels(HorizontalLabels);
|
||||
PartsTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
|
||||
std::vector<int> InfoTotals(PartsList.size());
|
||||
std::vector<int> ColorTotals(NumColors);
|
||||
std::vector<int> ColorTotals(ColorCount);
|
||||
int Row = 0, Total = 0;
|
||||
|
||||
for (const auto& PartIt : PartsList)
|
||||
{
|
||||
table->setItem(Row, 0, new lcPartsTableWidgetItem(PartIt.first->m_strDescription));
|
||||
PartsTable->setItem(Row, 0, new lcPartsTableWidgetItem(PartIt.first->m_strDescription));
|
||||
|
||||
for (const auto& ColorIt : PartIt.second)
|
||||
{
|
||||
|
@ -93,43 +101,43 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget* Parent, lcPropertiesDialogOpti
|
|||
|
||||
lcPartsTableWidgetItem* Item = new lcPartsTableWidgetItem(QString::number(Count));
|
||||
Item->setTextAlignment(Qt::AlignCenter);
|
||||
table->setItem(Row, ColorColumns[ColorIndex] + 1, Item);
|
||||
PartsTable->setItem(Row, ColorColumns[ColorIndex] + 1, Item);
|
||||
|
||||
InfoTotals[Row] += Count;
|
||||
ColorTotals[ColorColumns[ColorIndex]] += Count;
|
||||
Total += Count;
|
||||
}
|
||||
|
||||
for (int Column = 0; Column <= NumColors; Column++)
|
||||
if (!table->item(Row, Column))
|
||||
table->setItem(Row, Column, new lcPartsTableWidgetItem(QString()));
|
||||
for (int Column = 0; Column <= ColorCount; Column++)
|
||||
if (!PartsTable->item(Row, Column))
|
||||
PartsTable->setItem(Row, Column, new lcPartsTableWidgetItem(QString()));
|
||||
|
||||
Row++;
|
||||
}
|
||||
|
||||
lcPartsTableWidgetItem* Item = new lcPartsTableWidgetItem(tr("Total"));
|
||||
Item->mLast = true;
|
||||
table->setItem((int)InfoTotals.size(), 0, Item);
|
||||
PartsTable->setItem((int)InfoTotals.size(), 0, Item);
|
||||
|
||||
for (Row = 0; Row < (int)InfoTotals.size(); Row++)
|
||||
{
|
||||
lcPartsTableWidgetItem *item = new lcPartsTableWidgetItem(QString::number(InfoTotals[Row]));
|
||||
item->setTextAlignment(Qt::AlignCenter);
|
||||
table->setItem(Row, NumColors + 1, item);
|
||||
Item = new lcPartsTableWidgetItem(QString::number(InfoTotals[Row]));
|
||||
Item->setTextAlignment(Qt::AlignCenter);
|
||||
PartsTable->setItem(Row, ColorCount + 1, Item);
|
||||
}
|
||||
|
||||
for (int colorIdx = 0; colorIdx < NumColors; colorIdx++)
|
||||
for (int ColorIndex = 0; ColorIndex < ColorCount; ColorIndex++)
|
||||
{
|
||||
lcPartsTableWidgetItem *item = new lcPartsTableWidgetItem(QString::number(ColorTotals[colorIdx]));
|
||||
item->mLast = true;
|
||||
item->setTextAlignment(Qt::AlignCenter);
|
||||
table->setItem((int)InfoTotals.size(), colorIdx + 1, item);
|
||||
Item = new lcPartsTableWidgetItem(QString::number(ColorTotals[ColorIndex]));
|
||||
Item->mLast = true;
|
||||
Item->setTextAlignment(Qt::AlignCenter);
|
||||
PartsTable->setItem((int)InfoTotals.size(), ColorIndex + 1, Item);
|
||||
}
|
||||
|
||||
lcPartsTableWidgetItem *item = new lcPartsTableWidgetItem(QString::number(Total));
|
||||
item->mLast = true;
|
||||
item->setTextAlignment(Qt::AlignCenter);
|
||||
table->setItem((int)InfoTotals.size(), NumColors + 1, item);
|
||||
Item = new lcPartsTableWidgetItem(QString::number(Total));
|
||||
Item->mLast = true;
|
||||
Item->setTextAlignment(Qt::AlignCenter);
|
||||
PartsTable->setItem((int)InfoTotals.size(), ColorCount + 1, Item);
|
||||
}
|
||||
|
||||
lcQPropertiesDialog::~lcQPropertiesDialog()
|
||||
|
@ -139,9 +147,9 @@ lcQPropertiesDialog::~lcQPropertiesDialog()
|
|||
|
||||
void lcQPropertiesDialog::accept()
|
||||
{
|
||||
mOptions->Properties.mDescription = ui->descriptionEdit->text();
|
||||
mOptions->Properties.mAuthor = ui->authorEdit->text();
|
||||
mOptions->Properties.mComments = ui->commentsEdit->toPlainText();
|
||||
mOptions->Properties.mDescription = ui->DescriptionEdit->text();
|
||||
mOptions->Properties.mAuthor = ui->AuthorEdit->text();
|
||||
mOptions->Properties.mComments = ui->CommentsEdit->toPlainText();
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
struct lcPropertiesDialogOptions
|
||||
{
|
||||
lcModelProperties Properties;
|
||||
|
||||
lcPartsList PartsList;
|
||||
lcBoundingBox BoundingBox;
|
||||
};
|
||||
|
||||
namespace Ui
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="authorEdit"/>
|
||||
<widget class="QLineEdit" name="AuthorEdit"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
|
@ -48,7 +48,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="descriptionEdit"/>
|
||||
<widget class="QLineEdit" name="DescriptionEdit"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
|
@ -58,7 +58,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QTextEdit" name="commentsEdit">
|
||||
<widget class="QTextEdit" name="CommentsEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
|
@ -70,6 +70,20 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Measurements:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="MeasurementsLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabParts">
|
||||
|
@ -78,7 +92,7 @@
|
|||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QTableWidget" name="partsTable">
|
||||
<widget class="QTableWidget" name="PartsTable">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
|
@ -115,10 +129,10 @@
|
|||
<tabstops>
|
||||
<tabstop>tabWidget</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
<tabstop>authorEdit</tabstop>
|
||||
<tabstop>descriptionEdit</tabstop>
|
||||
<tabstop>commentsEdit</tabstop>
|
||||
<tabstop>partsTable</tabstop>
|
||||
<tabstop>AuthorEdit</tabstop>
|
||||
<tabstop>DescriptionEdit</tabstop>
|
||||
<tabstop>CommentsEdit</tabstop>
|
||||
<tabstop>PartsTable</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
|
Loading…
Add table
Reference in a new issue