Added model measurements. Fixes #631.

This commit is contained in:
Leonardo Zide 2021-02-28 15:57:02 -08:00
parent d0404d9fbb
commit 140daced93
6 changed files with 93 additions and 51 deletions

View file

@ -3177,7 +3177,7 @@ lcVector3 lcModel::GetSelectionOrModelCenter() const
{ {
lcVector3 Min(FLT_MAX, FLT_MAX, FLT_MAX), Max(-FLT_MAX, -FLT_MAX, -FLT_MAX); 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; Center = (Min + Max) / 2.0f;
else else
Center = lcVector3(0.0f, 0.0f, 0.0f); Center = lcVector3(0.0f, 0.0f, 0.0f);
@ -3253,7 +3253,25 @@ bool lcModel::GetSelectionCenter(lcVector3& Center) const
return Selected; 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; bool Valid = false;
Min = lcVector3(FLT_MAX, FLT_MAX, FLT_MAX); 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); 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; Center = (Min + Max) / 2.0f;
else else
Center = lcVector3(0.0f, 0.0f, 0.0f); Center = lcVector3(0.0f, 0.0f, 0.0f);
@ -4276,6 +4294,7 @@ void lcModel::ShowPropertiesDialog()
lcPropertiesDialogOptions Options; lcPropertiesDialogOptions Options;
Options.Properties = mProperties; Options.Properties = mProperties;
Options.BoundingBox = GetAllPiecesBoundingBox();
GetPartsList(gDefaultColor, true, false, Options.PartsList); GetPartsList(gDefaultColor, true, false, Options.PartsList);

View file

@ -257,7 +257,8 @@ public:
bool GetFocusPosition(lcVector3& Position) const; bool GetFocusPosition(lcVector3& Position) const;
lcObject* GetFocusObject() const; lcObject* GetFocusObject() const;
bool GetSelectionCenter(lcVector3& Center) 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; std::vector<lcVector3> GetPiecesBoundingBoxPoints() const;
void GetPartsList(int DefaultColorIndex, bool ScanSubModels, bool AddSubModels, lcPartsList& PartsList) const; void GetPartsList(int DefaultColorIndex, bool ScanSubModels, bool AddSubModels, lcPartsList& PartsList) const;
void GetPartsListForStep(lcStep Step, int DefaultColorIndex, lcPartsList& PartsList) const; void GetPartsListForStep(lcStep Step, int DefaultColorIndex, lcPartsList& PartsList) const;

View file

@ -632,7 +632,7 @@ lcVector3 lcView::GetCameraLightInsertPosition() const
lcVector3 Min, Max; lcVector3 Min, Max;
lcVector3 Center; lcVector3 Center;
if (ActiveModel->GetPiecesBoundingBox(Min, Max)) if (ActiveModel->GetVisiblePiecesBoundingBox(Min, Max))
Center = (Min + Max) / 2.0f; Center = (Min + Max) / 2.0f;
else else
Center = lcVector3(0.0f, 0.0f, 0.0f); Center = lcVector3(0.0f, 0.0f, 0.0f);
@ -1875,7 +1875,7 @@ void lcView::DrawGrid()
int MinX, MaxX, MinY, MaxY; int MinX, MaxX, MinY, MaxY;
lcVector3 Min(FLT_MAX, FLT_MAX, FLT_MAX), Max(-FLT_MAX, -FLT_MAX, -FLT_MAX); 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) if (mTrackTool == lcTrackTool::Insert)
{ {

View file

@ -43,12 +43,20 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget* Parent, lcPropertiesDialogOpti
setWindowTitle(tr("%1 Properties").arg(mOptions->Properties.mFileName)); setWindowTitle(tr("%1 Properties").arg(mOptions->Properties.mFileName));
ui->descriptionEdit->setText(mOptions->Properties.mDescription); ui->DescriptionEdit->setText(mOptions->Properties.mDescription);
ui->authorEdit->setText(mOptions->Properties.mAuthor); ui->AuthorEdit->setText(mOptions->Properties.mAuthor);
ui->commentsEdit->setText(mOptions->Properties.mComments); 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; const lcPartsList& PartsList = mOptions->PartsList;
QStringList horizontalLabels; QStringList HorizontalLabels;
std::vector<bool> ColorsUsed(gColorList.size()); std::vector<bool> ColorsUsed(gColorList.size());
@ -57,34 +65,34 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget* Parent, lcPropertiesDialogOpti
ColorsUsed[ColorIt.first] = true; ColorsUsed[ColorIt.first] = true;
std::vector<int> ColorColumns(gColorList.size()); 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++) for (size_t ColorIndex = 0; ColorIndex < gColorList.size(); ColorIndex++)
{ {
if (ColorsUsed[ColorIndex]) if (ColorsUsed[ColorIndex])
{ {
ColorColumns[ColorIndex] = NumColors++; ColorColumns[ColorIndex] = ColorCount++;
horizontalLabels.append(gColorList[ColorIndex].Name); HorizontalLabels.append(gColorList[ColorIndex].Name);
} }
} }
horizontalLabels.append(tr("Total")); HorizontalLabels.append(tr("Total"));
QTableWidget *table = ui->partsTable; QTableWidget* PartsTable = ui->PartsTable;
table->setColumnCount(NumColors + 2); PartsTable->setColumnCount(ColorCount + 2);
table->setRowCount((int)PartsList.size() + 1); PartsTable->setRowCount((int)PartsList.size() + 1);
table->setHorizontalHeaderLabels(horizontalLabels); PartsTable->setHorizontalHeaderLabels(HorizontalLabels);
table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); PartsTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
std::vector<int> InfoTotals(PartsList.size()); std::vector<int> InfoTotals(PartsList.size());
std::vector<int> ColorTotals(NumColors); std::vector<int> ColorTotals(ColorCount);
int Row = 0, Total = 0; int Row = 0, Total = 0;
for (const auto& PartIt : PartsList) 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) for (const auto& ColorIt : PartIt.second)
{ {
@ -93,43 +101,43 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget* Parent, lcPropertiesDialogOpti
lcPartsTableWidgetItem* Item = new lcPartsTableWidgetItem(QString::number(Count)); lcPartsTableWidgetItem* Item = new lcPartsTableWidgetItem(QString::number(Count));
Item->setTextAlignment(Qt::AlignCenter); Item->setTextAlignment(Qt::AlignCenter);
table->setItem(Row, ColorColumns[ColorIndex] + 1, Item); PartsTable->setItem(Row, ColorColumns[ColorIndex] + 1, Item);
InfoTotals[Row] += Count; InfoTotals[Row] += Count;
ColorTotals[ColorColumns[ColorIndex]] += Count; ColorTotals[ColorColumns[ColorIndex]] += Count;
Total += Count; Total += Count;
} }
for (int Column = 0; Column <= NumColors; Column++) for (int Column = 0; Column <= ColorCount; Column++)
if (!table->item(Row, Column)) if (!PartsTable->item(Row, Column))
table->setItem(Row, Column, new lcPartsTableWidgetItem(QString())); PartsTable->setItem(Row, Column, new lcPartsTableWidgetItem(QString()));
Row++; Row++;
} }
lcPartsTableWidgetItem* Item = new lcPartsTableWidgetItem(tr("Total")); lcPartsTableWidgetItem* Item = new lcPartsTableWidgetItem(tr("Total"));
Item->mLast = true; 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++) for (Row = 0; Row < (int)InfoTotals.size(); Row++)
{ {
lcPartsTableWidgetItem *item = new lcPartsTableWidgetItem(QString::number(InfoTotals[Row])); Item = new lcPartsTableWidgetItem(QString::number(InfoTotals[Row]));
item->setTextAlignment(Qt::AlignCenter); Item->setTextAlignment(Qt::AlignCenter);
table->setItem(Row, NumColors + 1, item); 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 = new lcPartsTableWidgetItem(QString::number(ColorTotals[ColorIndex]));
item->mLast = true; Item->mLast = true;
item->setTextAlignment(Qt::AlignCenter); Item->setTextAlignment(Qt::AlignCenter);
table->setItem((int)InfoTotals.size(), colorIdx + 1, item); PartsTable->setItem((int)InfoTotals.size(), ColorIndex + 1, Item);
} }
lcPartsTableWidgetItem *item = new lcPartsTableWidgetItem(QString::number(Total)); Item = new lcPartsTableWidgetItem(QString::number(Total));
item->mLast = true; Item->mLast = true;
item->setTextAlignment(Qt::AlignCenter); Item->setTextAlignment(Qt::AlignCenter);
table->setItem((int)InfoTotals.size(), NumColors + 1, item); PartsTable->setItem((int)InfoTotals.size(), ColorCount + 1, Item);
} }
lcQPropertiesDialog::~lcQPropertiesDialog() lcQPropertiesDialog::~lcQPropertiesDialog()
@ -139,9 +147,9 @@ lcQPropertiesDialog::~lcQPropertiesDialog()
void lcQPropertiesDialog::accept() void lcQPropertiesDialog::accept()
{ {
mOptions->Properties.mDescription = ui->descriptionEdit->text(); mOptions->Properties.mDescription = ui->DescriptionEdit->text();
mOptions->Properties.mAuthor = ui->authorEdit->text(); mOptions->Properties.mAuthor = ui->AuthorEdit->text();
mOptions->Properties.mComments = ui->commentsEdit->toPlainText(); mOptions->Properties.mComments = ui->CommentsEdit->toPlainText();
QDialog::accept(); QDialog::accept();
} }

View file

@ -5,8 +5,8 @@
struct lcPropertiesDialogOptions struct lcPropertiesDialogOptions
{ {
lcModelProperties Properties; lcModelProperties Properties;
lcPartsList PartsList; lcPartsList PartsList;
lcBoundingBox BoundingBox;
}; };
namespace Ui namespace Ui

View file

@ -38,7 +38,7 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLineEdit" name="authorEdit"/> <widget class="QLineEdit" name="AuthorEdit"/>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
@ -48,7 +48,7 @@
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLineEdit" name="descriptionEdit"/> <widget class="QLineEdit" name="DescriptionEdit"/>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
@ -58,7 +58,7 @@
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QTextEdit" name="commentsEdit"> <widget class="QTextEdit" name="CommentsEdit">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -70,6 +70,20 @@
</property> </property>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
<widget class="QWidget" name="tabParts"> <widget class="QWidget" name="tabParts">
@ -78,7 +92,7 @@
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QTableWidget" name="partsTable"> <widget class="QTableWidget" name="PartsTable">
<property name="editTriggers"> <property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set> <set>QAbstractItemView::NoEditTriggers</set>
</property> </property>
@ -115,10 +129,10 @@
<tabstops> <tabstops>
<tabstop>tabWidget</tabstop> <tabstop>tabWidget</tabstop>
<tabstop>buttonBox</tabstop> <tabstop>buttonBox</tabstop>
<tabstop>authorEdit</tabstop> <tabstop>AuthorEdit</tabstop>
<tabstop>descriptionEdit</tabstop> <tabstop>DescriptionEdit</tabstop>
<tabstop>commentsEdit</tabstop> <tabstop>CommentsEdit</tabstop>
<tabstop>partsTable</tabstop> <tabstop>PartsTable</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections> <connections>