Menu

[r171]: / specctra / cutil.cpp  Maximize  Restore  History

Download this file

160 lines (148 with data), 4.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*******************************************************************************
* Copyright (C) 2014 Pike Aerospace Research Corporation *
* Author: Mike Sharkey <mike@pikeaero.com> *
* *
* 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 at <http://www.gnu.org/licenses/> *
* for more details. *
* *
*******************************************************************************/
#include "cutil.h"
#include "cgpadstack.h"
#include "cpcbnet.h"
#include <QStringList>
static QPointF gSortPt; /** point for sorting relative to a point */
/**
* @param tm elapsed time in seconds.
* @return elased time in "hh:mm:ss" format.
*/
QString CUtil::elapsed(int tm)
{
QString rc;
int hour,min,sec;
hour=tm/3600;
tm=tm%3600;
min=tm/60;
tm=tm%60;
sec=tm;
rc.sprintf("%02d:%02d:%02d",hour,min,sec);
return rc;
}
/**
* @return the UNIT portion of a UNIT-PIN formatted reference string.
*/
QString CUtil::unitRef(QString unitPinRef)
{
QString rc;
QStringList parts = unitPinRef.split("-");
if ( parts.count() == 2 )
{
rc = parts.at(0);
}
return rc;
}
/**
* @return the PIN portion of a UNIT-PIN formatted reference string.
*/
QString CUtil::pinRef(QString unitPinRef)
{
QString rc;
QStringList parts = unitPinRef.split("-");
if ( parts.count() == 2 )
{
rc = parts.at(1);
}
return rc;
}
/**
* @return a UNIT-PIN string from UNIT and PIN.
*/
QString CUtil::placeRef(QString unitRef, QString pinRef)
{
QString rc;
rc = unitRef+"-"+pinRef;
return rc;
}
/**
* @return sorted padstack list
*/
static bool comparePadstackPosAscending(CGPadstack* s1,CGPadstack* s2)
{
QPointF p1 = s1->origin() - gSortPt;
QPointF p2 = s2->origin() - gSortPt;
double len1 = p1.manhattanLength();
double len2 = p2.manhattanLength();
return len1 < len2;
}
static bool comparePadstackPosDescending(CGPadstack* s1,CGPadstack* s2)
{
QPointF p1 = s1->origin() - gSortPt;
QPointF p2 = s2->origin() - gSortPt;
double len1 = p1.manhattanLength();
double len2 = p2.manhattanLength();
return len1 > len2;
}
/**
* @brief sort a list of padstacks by their position relative to a specified point.
* @param pads The padstacks to sort.
* @param pt The point to use as a reference point.
* @param order The sorting order.
*/
int CUtil::sort(QList<CGPadstack*>& pads,QPointF pt, tSortOrder order)
{
gSortPt=pt;
if ( order == CUtil::Ascending)
qSort(pads.begin(), pads.end(), comparePadstackPosAscending);
else if ( order == CUtil::Descending)
qSort(pads.begin(), pads.end(), comparePadstackPosDescending);
return pads.count();
}
/**
* @return sorted net list
*/
static bool compareNetsPosAscending(CPcbNet* s1,CPcbNet* s2)
{
if ( s1->padstacks() > 0 && s2->padstacks() > 0 )
{
QPointF p1 = s1->padstack(0)->origin() - gSortPt;
QPointF p2 = s2->padstack(0)->origin() - gSortPt;
double len1 = p1.manhattanLength();
double len2 = p2.manhattanLength();
return len1 < len2;
}
return false;
}
static bool compareNetsPosDescending(CPcbNet* s1,CPcbNet* s2)
{
if ( s1->padstacks() > 0 && s2->padstacks() > 0 )
{
QPointF p1 = s1->padstack(0)->origin() - gSortPt;
QPointF p2 = s2->padstack(0)->origin() - gSortPt;
double len1 = p1.manhattanLength();
double len2 = p2.manhattanLength();
return len1 > len2;
}
return false;
}
/**
* @brief sort a list of nets by their position relative to a specified point.
* @param nets The nets to sort.
* @param pt The point to use as a reference point.
* @param order The sorting order.
*/
int CUtil::sort(QList<CPcbNet*>& nets,QPointF pt, tSortOrder order)
{
gSortPt=pt;
if ( order == CUtil::Ascending)
qSort(nets.begin(), nets.end(), compareNetsPosAscending);
else if ( order == CUtil::Descending)
qSort(nets.begin(), nets.end(), compareNetsPosDescending);
return nets.count();
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.